Riyuzak251097's blog

By Riyuzak251097, history, 5 years ago, In English

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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

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.

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    hmm it looks so.. interesting things .. got to know about this.. i changed the v1.size() to long long variable and then subtracted 2 from it.. it worked.. which means ya it is case of underflow.. really thanks for the help