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

Автор shreypandey, история, 7 лет назад, По-английски

Hi guys, I am just starting to code in C++. I keep hitting a runtime error for my solution 28288661. It works fine on Ideone, for the 2nd testcase, which is where it fails on Codeforces. Can someone help me?

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

»
7 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

arr[i].size() is an unsigned value (size_t), and arr[i].size()-1 may overflow if arr[i] is empty, which is what happens on the second case. You can check that if you add assert(!arr[i].empty()). After such overflow your program will yield array out-of-bounds-based undefined behavior.