Moderator: Board moderators
Now I think that this question is not very meaningful... It's like nearly impossible to be solved without a good algorithm book at home...Adrian Kuegel wrote:It seems the problem limits were changed. Now there are up to 1000 queries.
And with KMP you have to go through the text now up to 1000 times, and that is too much.
So it seems that now you have to use Aho-Corasick (with this algorithm it is sufficient to go through the text once for a given set of patterns).
Adrian Kuegel wrote:It seems the problem limits were changed. Now there are up to 1000 queries.
And with KMP you have to go through the text now up to 1000 times, and that is too much.
So it seems that now you have to use Aho-Corasick (with this algorithm it is sufficient to go through the text once for a given set of patterns).
Aho-Corasick have complexity O(m + z), where z is the number of pettern occurences. So, there are many tests where z = O(km). In such test cases Aho-Corasick algo is not better than KMP. But AC algo can be modifed in a such way, that it would have complexity O(m + k) for a current problem.
What's about memory? There is not any good test for checking memory usage. It is very hard to run under 32 MB. If you were not belive me try this test
How could you speed your program?
That's because someone introduced characters different than
alphabetic chars and digits (which are not allowed).
Users browsing this forum: No registered users and 1 guest