Bug in the code?

here is the link : https://repl.it/LeL8/0
problem is flipcoin of difficulty level medium.
though code is working fine on test cases but it’s showing wrong answer.

In the lines, 19-20 and 52-53 just change this

lazy[2*i] = true;
lazy[2*i+1] = true;

to this

lazy[2*i] = !lazy[2*i];
lazy[2*i+1] = !lazy[2*i+1];

and your code will get accepted.

The reason is that lazy[i] being TRUE doesn’t mean that lazy[2 * i] and lazy[2 * i + 1] have to be FALSE. Thus, the second way is the correct way to flip the boolean values.

Here is your accepted code:

https://www.codechef.com/viewsolution/15544381

1 Like