Editorial for DMOPC '22 Contest 3 P6 - Compressibility
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
It suffices to compute the repeatability of each of the substrings in time. This can be done by iterating over all possible periods and checking whether each period is valid via hashing.
Time Complexity:
Subtask 2
There are many approaches here. One possible solution is to iterate over all possible starting points and periods, using binary lifting and hashing to compute the maximum repetition.
Time Complexity:
Subtask 3
We optimize the solution from the previous subtask by modifying the Main-Lorentz algorithm. We first generate all batches of repetitions, and sort them in increasing order of length. For each batch of repetitions, we iterate through all possible starting points, using binary lifting and hashing to see how far the repeats go. However, doing this naively yet again yields an , since the number of repetitions can be up to . The key observation now is that if there is a repetition of length starting at a certain position, the next longest repetition starting at the same position must have length around . With this observation, each starting position will be processed at most times, yielding an solution overall. Correct implementation of this algorithm requires some further insights that will be left as an exercise for the reader.
Time Complexity:
Alternate Solution
Note that every substring with a repeatability greater than belongs to a unique run in the string. Using an algorithm that can enumerate over all of the runs, we can easily compute the compressibility using some elementary math.
Time Complexity: or
Remarks: The alternate solution using run enumeration was discovered by
just two days before the contest, far too late to consider replacing the problem. Although it almost completely trivializes the problem, we assumed the algorithm was obscure enough that it would not be too big of a deal. Unfortunately though, many of our top contestants this time were well aware of the algorithm, making the problem boring and turning it into a simple knowledge test. Better luck next time...
Comments