|
0
it's specified in the question that there is only one root in the range (-1,1) |
|
0
At r=-1, the value of the polynomial is clearly positive, because cm is positive. And since there is only one root in the range -1<r<1, thus the polynomial has one root dividing the function into two parts. That is why you can do binary search. |
|
0
I solved Div2 A and Div2 C easily, but for some reason I had quite a lot of trouble with Div2 B. The only way I could think of in the end was to keep swapping integer arrays to denote swap of two letters. Does anyone have a better way ? |
|
+6
Notice that any substring containing more than one consecutive zeroes/ones will remain as it is, so the only case we have to think about is 10101... If you notice carefully, after each move the leftmost and the rightmost digit of this substring will become safe (it will become equal to whatever is beyond it), so you can easily come up with a O(N) solution. So we just have to update cnt as max(cnt,(length of unsafe substring+1)/2)) |