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 1324. Extra Spaces

Bit of help
Posted by jk_qq 13 Oct 2017 20:57
Nice problem.
Playing out with small numbers and sample could help in sequence instantiation.

My solution is only 30 lines of c++ code O(L) though.

Hint: imagine we have sequence which can replace up to L spaces afterall. Then to enlarge our sequence we insert L/2 + 1 in the beginning. Maximum L could be computed via straightforward iteration starting from lax max_L
Example:

seq: 2
max_L: 2

seq: 2, 2/2 + 1 = 2, 2
max_L: 2, 4

seq: 2, 2, 4/2 + 1 = 2, 2, 3
max_L: 2, 4, 10

seq: 2, 2, 3, 10/2 + 1 = 2, 2, 3, 6
max_L: 2, 4, 10, 40

Etc.
GL.