souravvv's blog

By souravvv, history, 3 years ago, In English

I was practicing this problem. Now, following events occurred in chronological order (Along with other submissions, these are key submissions to my question)

  1. This code received verdict WA on 4.
  2. This code received verdict RTE on 3.
  3. This code received AC

From 2 to 3, (RTE to AC) I only changed one thing, while looping over a vector in reverse order, I was using the following loop construct

for(ll i = v.size()-1; i >= 0; i--)

But after I realized that the v.size() is unsigned, so I might have to convert to (ll) first. So changing the loop to the following code got me AC.

for(ll i = (ll)v.size()-1; i >= 0; i--)

Here is the diff between the RTE code and AC code.

Now, I had made the same mistake when I received WA on 4. That means without type casting to ll, my code passed the case 3. (Because it received WA on 4). But shouldn't the same code receive RTE on 3??

Here is the diff between the WA code and RTE code.

Is it just undefined behavior? Or there is a specific reason behind this?

Can anyone help me by explaining this?

Full text and comments »

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