Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

deekshas15's blog

By deekshas15, history, 3 years ago, In English

I tried solving 674 d

it gives a correct answer on my pc but runtime error on codeforces could anyone help me with this issue? https://codeforces.com/contest/1426/submission/115914494

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

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

Try putting the for loop that iterates over the pos vector in an if statement like

if(pos.size()>0){
        for(li i=pos.size()-1;i>=0;i--){
            if(pos[i]<mic){count++;mic=pos[i];}
        }
}

this made the runtime error not happen in custom invocation.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    That is the bug, but you should have mentioned why this is a bug. pos.size() returns a value that is not of type int but of type size_t, which is an unsigned type. If the array is empty and you subtract 1 from its size, you get (size_t)-1 which is 2^64-1 on most computers, so you access the array at index 2^64-1.

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

      I see, I didn't know that that's what caused it, thanks a lot for the explanation!