Editorial for IOI '06 P1 - Deciphering the Mayan Writing
Submitting an official solution before solving the problem yourself is a bannable offence.
The contestant should note that any solution that actually tries to match every possible permutation of
OPTIMAL SOLUTION: The optimal solution uses a queue where it pushes consecutive characters of
- A character
that does not appear in is in the queue. - The number of times a character
, that appears in , is in the queue exceeds the number of times that character appears in .
After an error condition is reached, characters are popped from the queue until the error condition is cleared. In order to check for an error condition, the optimal solution keeps two vectors of length equal to the alphabet, each entry corresponds to a character in the alphabet. These two vectors maintain the number of times each character appears in
If at any time the length of the queue is equal to the length of
Since every character in
SOLUTION 2: Instead of keeping two vectors to check for an error condition, every time a character is pushed or popped from the queue check every character in the alphabet to catch an error condition. This solution yields a complexity
SOLUTION 3: Starting from every position in
Comments