Блог пользователя ftiasch

Автор ftiasch, 14 лет назад, По-английски

http://main.edu.pl/en/archive/pa/2011/naj

problem: find length of shortest period after removing exactly one character from the given string.

the period of string s is the shortest string t which s is a prefix of tk for sufficiently large k, where tk denotes t + t + ... + t (k times).

i have already got some idea of the algorithm, is there any algorithm running in O(N) time?

thanks in advance.

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
14 лет назад, скрыть # |
 
Проголосовать: нравится -33 Проголосовать: не нравится

You have to use segment tree and BS Tree their subtrees' roots being hashed (using perfect hashing !) and finally BS on answers while also balancing the red-black tree, and maintaining the fact that the sum is even if the number of subtrees' nodes are 2^p-1, where p is any prime number.

Also take into account that 64MB stack is not enough to recursively solve the problem. You gotta use an iterative method.

»
14 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can you explain your O(NLogN) idea? May be we can improve it to O(n) together.