Page 1 of 5
902 - Password Search
Posted: Sat Sep 30, 2006 7:17 am
by Darko
I was going to write "gripe about 902", but that was taken already
First of all - input does not follow the specification, number and string don't have to be on the same line. I think I figured out how to read it properly, but it's TLE now.
I optimized my Java code as much as I could short of fiddling with I/O, but I/O alone is just 0.7 secs, shouldn't make that much of a difference.
This is what I do (n - number given (<=10), slen - length of the string):
- read string into an array (O(n))
- sort pointers to substrings (O(n*slen*log(slen)) <- bad?
- go through list of pointers and find the longest repeating sequence (O(n*slen))
I guess my algorithm is too slow, I am not sure what to do to speed things up. I was going to do it in C, but that would involve some learning on my part (strings, sorting,...), so I am trying to avoid it
If it can be done without sorting, please let me know. Oh, I did try using Hashtable, but it gives me MLE - it is just too expensive to use (on UVa, at least).
Re: 902 Password Search
Posted: Sat Sep 30, 2006 9:11 am
by Timo
Darko wrote:
Oh, I did try using Hashtable, but it gives me MLE - it is just too expensive to use (on UVa, at least).
I think your implementation of Hashtable is wrong.
I have use Hashtable too.. and it give me AC
Posted: Sat Sep 30, 2006 9:27 am
by Darko
I used java.util.Hashtable, I don't have my own.
So, that's the only way to solve it? I guess I'll have to reinvent yet another wheel

Posted: Sat Sep 30, 2006 11:31 am
by fpavetic
think about hashing so you can get rid of slen constant :: "To simplify things, you can assume that the text only includes lower case letters."
Posted: Sat Sep 30, 2006 3:01 pm
by Timo
Darko wrote:I used java.util.Hashtable, I don't have my own.
So, that's the only way to solve it? I guess I'll have to reinvent yet another wheel

don't store the substring in the hashtable, just store the value....
26^10 < 10^18
I hope you understand....

Posted: Mon Oct 02, 2006 6:09 am
by DJWS
Hi.
Could anyone help check the output of these cases?
2 ababcdcd
2 cdcdabab
10 a
1 a
--
DJWS, a newbie in programming

Posted: Mon Oct 02, 2006 12:41 pm
by Jan
I think your first two cases are wrong. Because then there would be a special judge for the problem.
The third case is also wrong, since you cant find a 10 letter password from a string with just one letter.
You can assume that 'N' is less than or equal to the length of the given string and there is always a unique password.
And for the final case the output is obviously 'a'.
Re: 902 Password Search
Posted: Sat Oct 07, 2006 4:14 pm
by StanleY Yelnats
Timo wrote:
I think your implementation of Hashtable is wrong.
I have use Hashtable too.. and it give me AC
I used Rabin Karp method for hashing but it gave me a WA
what is your method?
Posted: Mon Oct 09, 2006 2:08 pm
by Emilio
It can be solved with a simple qsort.
Posted: Tue Oct 10, 2006 9:45 pm
by StanleY Yelnats
well with a qsort you will have m*n element which results in O((mn)log(mn))
n = string lenght
m = password lenght
Posted: Wed Oct 11, 2006 11:56 pm
by Emilio
No, you will have n elements O((n)log(n)).
Exactly n-m+1 elements.
Each element can be of m as lenght, or you can solve it with only an array of chars and another array of char pointers.
Posted: Thu Oct 12, 2006 10:03 am
by StanleY Yelnats
Emilio wrote:No, you will have n elements O((n)log(n)).
Exactly n-m+1 elements.
Each element can be of m as lenght, or you can solve it with only an array of chars and another array of char pointers.
you're absolutely right
my mistake!

Re: 902 Password Search
Posted: Wed Oct 18, 2006 5:46 am
by Timo
StanleY Yelnats wrote:Timo wrote:
I think your implementation of Hashtable is wrong.
I have use Hashtable too.. and it give me AC
I used Rabin Karp method for hashing but it gave me a WA
what is your method?
sorry for late reply...
I used my own method to solve this problem ^ ^ (that's secret), but if you have used Rabin Karp it should give AC, maybe your implementation is wrong or there is a part of your code has wrong (maybe little mistake).
Posted: Sat Oct 28, 2006 12:59 pm
by rio
is there any tricky input? i can't get AC..
some i/o will help me.
thanks in advance.
---
sory for my poor english
Posted: Sat Oct 28, 2006 2:02 pm
by Jan
There are no special cases. Try the following i/o set...
Input:
Code: Select all
1 thequickbrownfoxjumpsoverthelazydog
3 thequickbrownfoxjumpsoverthelazydog
4 testingthecodetofindtheerrortestandtestagain
5 thearraycanbetoobigsobecarefulandtherecantberarecasescanbe
Output:
Hope it helps.