whatthemomooofun1729's blog

By whatthemomooofun1729, history, 19 months ago, In English

I was working on the problem 1371D — Grid-00100 and I submitted this code: 206708949. For some reason, Codeforces said that my code had an "out of bounds" error on line 79. I'm not sure why this error occurred, because my matrix indices are clearly within bounds. Additionally, on test case 8 of test 2, the checker comment was "wrong answer Integer -1849096384 violates the range [0, 18] (test case 8)", but I tested test case 8 locally and got the correct answer. Does anyone know why this could be happening? Your help is appreciated!

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Maybe the problem is with integer overflow not with the array index out of bound.

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

because my matrix indices are clearly within bounds — how you tested that?

assert(i < n && j < n && i>=0 && j >=0); — you know that it works only on Debug building, right?

a.rsz(N, vi(N, 0)); — you know that it only appends/remove items, not touching first min(a.size(), N) items, right?

  • »
    »
    19 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think assert() works when NDEBUG is not defined as a marco, which is also the case in CF.

    Btw, the problem also seems to be a.rsz(N, vi(N, 0)); to me.

    • »
      »
      »
      19 months ago, # ^ |
      Rev. 2   Vote: I like it +5 Vote: I do not like it

      Yes, my bad, with assert assert(i < A.size() && j < A[i].size() && i>=0 && j >=0); OP's code terminates as expected.