c2h5sh's blog

By c2h5sh, history, 7 weeks ago, In English

Running this code locally gives Runtime Error on test 3 due to this:

s.erase(s.find(cnt));

Which I replaced by this:

auto itr = s.find(cnt);
    if (itr != s.end())
        s.erase(itr);

And it passed all test.

It took me less than a minute to figure out that deletion might be causing RE.

But during the contest, I spent more than an hour thinking about why it was giving TLE.

Is this normal behaviour on Codeforces compilers or is it a bug. If it's normal, then how do we deal with such verdicts (a TLE which actually is just a RE)?

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it -21 Vote: I do not like it

That is really unfortunate bro, it definitely isn't TLE, it clearly was a Runtime Error, but the system showed a wrong verdict

»
7 weeks ago, # |
  Vote: I like it +18 Vote: I do not like it

Actually this is not guaranteed to be runtime error, as this operations causes undefined behavior. And undefined behavior is just that, undefined. You could have got any verdict

»
7 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

This same problem happened to me on pretest 3 and I thought my solution was too slow because of the judge's verdict. It is unfortunate that it gave me TLE because if it had given me RTE, I might've had a better idea of what to debug. It was simply my fault for not understanding the STL and the undefined behavior :(.