ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1684. Jack's Last Word

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?
Posted by Alex Tolstov 1 Mar 2009 00:30
use z-algorithm
Re: How I can solve it without hash?
Posted by Mikhail Lopatkin [NNSTU1] 1 Mar 2009 01:04
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?
Posted by Sandro (USU) 1 Mar 2009 16:08
Why n times? Jury solution calculates prefix-function only one time.
Re: How I can solve it without hash?
Posted by SkorKNURE 8 Mar 2009 21:52
Can you explain your solution via KMP prefix func? Thanks!
Re: How I can solve it without hash?
Posted by тупой лосось 14 Mar 2009 16:48
+1
i wrote it, but have tl..
Re: How I can solve it without hash?
Posted by NotImplemented 17 Mar 2009 20:53
I solved it using z-algorithm.

Edited by author 23.03.2009 17:26
Re: How I can solve it without hash?
Posted by DK [Samara SAU 1: X2008] 19 Apr 2009 19:46
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