ARIF_30's blog

By ARIF_30, history, 21 month(s) ago, In English

"Are the conditions 'if(sum%2)' and 'if(sum%2==1)' the same? If not, could you please clarify the matter? If they are the same, I have two submissions, one is accepted (AC) and the other is rejected (WA), but the only difference between them is the use of the two aforementioned conditions. I would be grateful if someone could help me with this." https://mirror.codeforces.com/contest/1807/submission/199213689 (Accepted). https://mirror.codeforces.com/contest/1807/submission/199213510 (Wrong Answer).

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
21 month(s) ago, # |
  Vote: I like it +3 Vote: I do not like it

It is possible that the value sum is becoming negative and hence its mod 2 is -1 instead of 1. So if you want to test for even or odd, either check for sum % 2 == -1 or 1, or take mod with absolute value of sum.

PS : I submitted your code with the above changes and it got accepted. This

Hope it Helps.

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Yes, I understand the matter. Thank you for such a helpful response.