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

Автор Real_Father_Of_Ash, 3 года назад, По-английски

The official analysis is hard to understand. Any other explanations please?

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

»
3 года назад, # |
  Проголосовать: нравится +31 Проголосовать: не нравится

First notice that it is easier understand the operation when you compress the string. Compressing a string is just grouping adjacent characters, so "110001" will be compressed into [2, 3, 1] because it has 2 ones, then 3 zeros and finally a single one.

Then, when you have a compressed string $$$(k_i)_{1\le i\le n}$$$, a not operation removes the first element of the sequence, while a double operator makes $$$n$$$ even and adds 1 to the last element of the sequence.

Notice that with operations not, you will remove a prefix of the initial string, so you can iterate on the length of the prefix you remove. What is left must be equal to a prefix of the wanted string (except potentially the last character). Then it's just some case analysis to complete the prefix (delete the prefix and double to make the correct solution).