vivek_ghosh's blog

By vivek_ghosh, history, 3 months ago, ,

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

•
• -1
•

 » 3 months ago, # |   0 Auto comment: topic has been updated by vivek_ghosh (previous revision, new revision, compare).
 » 3 months ago, # |   +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.
•  » » 3 months ago, # ^ |   +3 Thanks.Got it!
 » 3 months ago, # |   +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.
 » 3 months ago, # |   +1 Thanks.
•  » » 3 months ago, # ^ | ← Rev. 3 →   +1 With pleasure. Another alternative to write the same loop is for( auto iu = it; it != f.end(); it = iu ) { iu++; if ( ( x % *it ) and ( y % *it ) ) f.erase( it ); }