Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

Автор tristansun, история, 20 месяцев назад, По-английски

You're given a binary string. You can delete two equal adjacent characters however many times you like. Is it true that no matter how you delete adjacent characters, there is a unique shortest string that you can end up with?

I've been stuck on this for a while now. I suspect that the answer is yes, but I have no idea how to prove it. Please help me prove or disprove.

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

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

noone solves these hard things

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Go touch some grass, bro. The obvious counter example is 001 in which you can end up with both 0 and 1 at the end.

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится -13 Проголосовать: не нравится

Idk why but this lowkey feels AI generated

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Final string will match regexp 0?(10)*1?. After all pairs of 00 and 11 eliminated total length will be the same. To make both 1010... and 0101... from same string by deleting pairs is impossible

»
20 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

The answer is yes. Proof:

The only two possible resulting strings are 1010... and 0101... Consider a reversal of the process: starting with the end string and adding pairs of adjacent characters to produce the original string. It is impossible for to produce the same string from both of these resulting strings, so only one of them is a possible result.

»
20 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +57 Проголосовать: не нравится

Flip every character on an even position, now the problem is that the operation is removing 10 or 01(since you're removing 2 characters at a time all other parities of positions are preserved, so doing this operation is just removing a 01 or 10 without the rest of the string being affected). You can always do that until the string is all 0s or all 1s. Let's say there are $$$x$$$ zeroes and $$$y$$$ ones in the new string. If $$$x \gt y$$$, the answer to the original problem is 01010... of length $$$x-y$$$, if $$$x \lt y$$$ it's 10101... of length $$$y-x$$$.

»
14 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This is true for strings of any kind, not just binary strings.

»
14 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

the answer is YES

short but understandable proof:

the string will look like this:

000... 111... 000... 111..

with each move you will decrease size of one segment by one so you always end up with 10101... (the lenght is number of segments)

you can use this proof for normal string too!