Блог пользователя deekshas15

Автор deekshas15, история, 3 года назад, По-английски

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

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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 года назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    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.