How I can solve it without hash?
Posted by
vgu 1 Mar 2009 00:08
I solve this task during contest with greedy+hash. My solution take O(n) time, but i'm interest how i can solve this without hash?
Re: How I can solve it without hash?
use z-algorithm
Re: How I can solve it without hash?
You can use prefix function from KMP algorithm.
Re: How I can solve it without hash?
Posted by
Lomir 1 Mar 2009 02:30
Simple KMP on suffixes will TLE on good tests, cause u will need to run it n times.
This problem has very weak tests.
My first idea was to use naive suffix finding algorithm for short suffix and only if there is no short (with length about 500) common suffixes then run KMP and find long one.
However I managed to get AC only with naive suffix finding algo.
Re: How I can solve it without hash?
Why n times? Jury solution calculates prefix-function only one time.
Re: How I can solve it without hash?
Can you explain your solution via KMP prefix func? Thanks!
Re: How I can solve it without hash?
+1
i wrote it, but have tl..
Re: How I can solve it without hash?
I solved it using z-algorithm.
Edited by author 23.03.2009 17:26
Re: How I can solve it without hash?
How to solve it with one kmp:
a) find kmp(s1+"#"+s2)
b) if there is 0 kmp-value at any position in s2, "Yes"
c) use the fact that you can stop every prefix at any time, i.e. abrab, b is 'bad' letter, so you can output abr and continue with prefix ab