Strange C++ behavior

Revision en2, by SaBuZa, 2016-06-15 21:10:20

Because my friend's English is not very good, I am asking this question on his behalf.

He says on problem E of yesterday's round, he was debugging and finally got accepted but found that he could only get accepted with a debugging if statement that is supposed to be useless.

When he removes the if statement, it gets wrong answer on test case 38. However, when the if statement is included (highlighted in green in the image), it is accepted but the commands in the if statement are not even executed.

It is very confusing for me that the addition of an if statement that does nothing to change the values of any variables could change the output of the program.

The two submissions can be found here: http://codeforces.com/contest/681/submission/18481671 (Accepted with if statement) http://codeforces.com/contest/681/submission/18481662 (Wrong answer without if statement)

Does anyone have any explanation for this phenomenon?

Tags c++

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English SaBuZa 2016-06-15 21:10:20 96 Tiny change: 'enomenon? ' -> 'enomenon? \n\n![ ](http://codeforces.com/1ebd5b/1.jpg)'
en1 English SaBuZa 2016-06-15 21:07:59 974 Initial revision (published)