masaow's blog

By masaow, history, 5 years ago, In English

I am trying to solve 1287C - Garland I wrote 70338791 It's working fine on my machine but showing runtime error on codeforces. Can someone explain me why this is happening.

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I didnt read your code completely, but in the first line of your solve() function, you mentioned _odd and _even can contain the value -1 . so it may happen something like this, dp[idx][-1][1][last] ..

  • »
    »
    5 years ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    But why is it working in my machine.

»
5 years ago, # |
Rev. 7   Vote: I like it +1 Vote: I do not like it

The following update fixed your solution.

70350376

The exit code in the run-time error is a segmentation fault that is raised when one of the indices of the dp array is out-of-range. Your soluton obviously processed the memory locations outside the valid memory space allocated to the dp array in your machine without raising a segmentation fault. This may happen in some machines, but the fault may be detected when running the code in another place.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    or see this and fix that code (always debug by yourself please)

    next time use codeforces CUSTOM INVOCATION to check your RTE code not on your computer

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Thanks A lot .Got my mistake :) .