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

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

I was solving Problem 777D .. i had submitted my code for the problem but it gives runtime error for test case 5. The error occurs in case the input has only 1 string.. i handled the case for n = 1 and it worked. But still curious to find why my initial code did not work and gave a runtime error as when i ran test case 5 on my local machine and on online ide's they did not show runtime error.

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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

v1.size() returns an unsigned integral type, according to cplusplus.com/reference/vector/vector/size/. So when n is 1 (and v1.size() is 1), then subtracting 2 will cause integer underflow. I don't know why this still worked on some machines, since to the best of my knowledge ctr should have become INT_MAX or LLONG_MAX, which would have crashed the program when you tried to use it as an index. But I might be wrong.

At the very least, CodeForces's system does not like either the underflow or usage of some massive value as an index, so that caused Runtime Error.