### willtryagain's blog

By willtryagain, history, 10 days ago, ,

In the problem good string([https://codeforces.com/problemset/problem/1389/C]) I made two observations- 1. When n is odd then all characters are equal ~~~~~ 2. Else

s1 = s3 = ... = sn ~~~~~

s2 = s4 = ... = sn-1 ~~~~~

It means the string is fixed by the first two starting characters. I iterated from 0 to 9 for the first two characters and found the count of positions-

- if i is odd and si != s1 or

• i is even and si != s2 ~~~~~

My answer is off by one in some test cases. I want to a small test string where I could find the reason.

• -15

 » 10 days ago, # |   0 Auto comment: topic has been updated by willtryagain (previous revision, new revision, compare).
 » 10 days ago, # |   0 Did you took min of both counts? My submission
 » 10 days ago, # | ← Rev. 2 →   0 If you are taking an alternating sequence then the length of the sequence must be even.Eg: 59595Here the alternating sequence is of length 5 but we need an even length if we are alternating so ans will be 4. But if you are taking all same chars then it can odd or even, no matter. if(len%2!=0 && i!=j) len--; //if length of sequence is odd and it is alternating(i!=j), take len-- This may be the reason your answers are off by only 1.My submission : Good String
 » 10 days ago, # | ← Rev. 3 →   +8 I am pretty sure that if all the numbers are the same (i.e. aaaaa...), then it can have any length, odd or even. If the numbers are in alternating order (i.e. ababab...), then it HAS to be even. This is my submission -> https://codeforces.com/contest/1389/submission/88384839If you want it. Test this string out:1233330985The optimal answer is to remove everything except for the EVEN amount of 3's
 » 10 days ago, # |   0 I remember this issue, say you find alternating sequence of length K, but K is odd, then you take one less to make it even.you can just say K = K / 2 * 2