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.
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 knowledgectr
should have becomeINT_MAX
orLLONG_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.
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