grzinicdino's blog

By grzinicdino, history, 5 hours ago, In English

I've written my solution for this task https://codeforces.net/contest/702/problem/A When I submitted it I got the wrong answer on test 1 https://codeforces.net/contest/702/submission/287285925 My code outputs 4, instead of 3 which is the correct answer.

I reran the exact same code using the same input as in test 1 but got 3. I even tried to run it on a few online cpp compilers but they all still outputted 3. So my question is, how come only on Codeforces does my code output 4 instead of 3? Could it be that my code uses something that is not supported on Codeforces or have I simply made a mistake in my code?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 hours ago, # |
Rev. 2   Vote: I like it +6 Vote: I do not like it

Inconsistent outputs for the same inputs (in the absence of using random functions) typically means something in the code is causing undefined behaviour — looking at your code a likely candidate is accessing an element out of bounds. Are you sure that on a[x] >= a[x + 1] the value of x+1 is always in bounds?