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 1590. Bacon’s Cipher

About the solving approach(+)
Posted by SPIRiT 29 Oct 2007 21:43
I know that suffix trees can be used for such problem. How about using a large hash table for storing codes of substrings that we already have? Anyone got AC in that way?
Re: About the solving approach(+)
Posted by svr 29 Oct 2007 22:16
I trying during a long time O(n) suffix tree of Ekkonen
but could'n catch all details. I think that you
question has the same nature. If you think about
yourself as good coder you should catch O(n) suffix tree.
Re: About the solving approach(+)
Posted by Vedernikoff Sergey 30 Oct 2007 17:40
I tried double-hash of about 30000 elements each but WA. Nevertheless, some people claim the problem may be solved with hash.
Re: About the solving approach(+)
Posted by Lomir 13 Nov 2007 04:25
How do you calculate hash for n^2 substrings?
I calculate hash seperately for each lenth os substring by:
hashcode = prime^n*c1 + prime^(n-1)*c2 + prime^(n-2)*c1...

string movement is by 1 char:
newhashcode = (oldhashcode - prime^n*removedchar)*prime + prime*addedchar

This gets TLE 3.
Re: About the solving approach(+)
Posted by Brainfuck 16 Jul 2009 16:31
I use 'poganyi hash'. And it works very good. Yeah, baby!
Re: About the solving approach(+)
Posted by SPIRiT 6 Aug 2009 00:46
Finally managed to implement the Ukkonen algo correctly - worked from the first try and is much faster now, than with O(N^2) implementation. Here is my status board to examine:

 http://acm.timus.ru/status.aspx?space=1&num=1590&author=33910

Edited by author 06.08.2009 00:47

Edited by author 06.08.2009 00:48
Re: About the solving approach(+)
Posted by Oracle[Lviv NU] 6 Aug 2010 03:47
to Lomir: you should not use sorting. Without sorting this approach gives AC in 0.454 sec.
Re: About the solving approach(+)
Posted by AterLux 7 Sep 2010 20:51
Calculation of hash for each substring will take O(N^2). Then you need to check non-equal of string with same hash. For example for test 'aaaaaaaaaaaaa' (and longer) every substring of same length will have same hash code
Re: About the solving approach(+)
Posted by Sushil Nath 24 Jun 2011 01:17
Can it be done using ternary search tree