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 1706. Cipher Message 2

Suffix automata
Posted by SergeiEgorov 7 Aug 2015 18:09
Is it possible to solve this problem using suffix automata? I got TL5.
But I think that O(N * K) solution have to work faster. Am I wrong? Thanks.

PS. Got AC with KMP O(N * K).

Edited by author 26.08.2015 00:30
Re: Suffix automata
Posted by Mahilewets 12 Jul 2017 10:20
Just got AC with suffix automation.  0.95 sec,  1.5MegaBytes.
Nothing tricky,  just avoided STL.
Construct an automation for every window and find number of different  paths.
I think my program is pretty slow because when I am constructing an automation I am using modulo operation every step (before adding every new symbol)  to deal with cyclic shift.  Obviously it can be improved by checking whether i+k>len(s)  and branching.
Re: Suffix automata
Posted by Mahilewets 12 Jul 2017 10:28
Also my program is slow because I am allocating and deallocating an entire array for DAWG for every window.  Obviously it can be allocated once