Блог пользователя whatthemomooofun1729

Автор whatthemomooofun1729, история, 12 месяцев назад, По-английски

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!

  • Проголосовать: нравится
  • -7
  • Проголосовать: не нравится

»
12 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
12 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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?

  • »
    »
    12 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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.

    • »
      »
      »
      12 месяцев назад, # ^ |
      Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

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