I submitted two same codes for problem 949C - Data Center Maintenance. Initially, I chose Lang GNU C++14 but got RTE. After a while, I tried my luck, chose GNU C++11 and miraculously, got AC. Here are my codes:
Code with GNU C++14 : 36116002 (verdict RTE)
Code with GNU C++11 : 36116440 (verdict AC)
I have not found anything to explain it and I'm afraid that these things may happen during some future contests. Can you suggest any reasons? Thank you!
You dereference an iterator directly after erasing it
Thank you! I got it! However, it's really weird that it was accepted with C++11!
The GNU C++11 compiled code run-time behavior seems to be the result of compile-time static code analysis that fixed the problem automatically using abstract interpretation, and has nothing to do with the standard invalid use of a
set::iterator
object after callingset::erase
to remove its associated element from the set.A closer examination of the contents of the
set::iterator
objectit
in the GNU C++14 compiled code after callingset::erase
should confirm this hypothesis.I have just checked your solution using GNU C++14 after swapping the
erase(it)
andinsert(*it)
statements in both branches of the if-statement ons[i]
, and the solution was accepted 36144333. You may check the following faster GNU C++17 solution 36150970 based onvector< int >
andvector< vector< int > * >
. The answers of the latter solution are also identical to the Jury's answers, even though any possible answer is sufficient when multiple answers exist to the input bit string.Xin chào anh cuom1999, nhớ em trên LQDOJ ko