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

Автор vivek_ghosh, история, 8 лет назад, По-английски

I submitted a solution to problem 1025B - Weakened Common Divisor .I'm getting Runtime Error "Exit code is -1073741819" for testcase 1.

Here's the submission link: 41911755

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by vivek_ghosh (previous revision, new revision, compare).

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

You erase a set iterator, that you still later use in a loop.

To prevent that, if you want to erase an element in a set, first increment the iterator pointing to that element, and then erase the iterator previous to it.

Also, when erasing an element, don't dereference the iterator.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Just replace the loop with something like that:

while( it != f.end() )
    if( x % (*it) and y % (*it) )
    { 
        auto iu = it; 

        iu++, f.erase(it), it = iu; 
    }
    else
        it++;

This should fix the problem. Either f.erase(it) or f.erase(*it) can be used to erase the item.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Thanks.