cuom1999's blog

By cuom1999, history, 6 years ago, In English

I submitted two same codes for problem 949C - Обновление дата-центров. 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!

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

»
6 years ago, # |
  Vote: I like it +6 Vote: I do not like it
S0.erase(it);
S1.insert(*it);

You dereference an iterator directly after erasing it

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

    Thank you! I got it! However, it's really weird that it was accepted with C++11!

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

      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 calling set::erase to remove its associated element from the set.

      A closer examination of the contents of the set::iterator object it in the GNU C++14 compiled code after calling set::erase should confirm this hypothesis.

»
6 years ago, # |
Rev. 10   Vote: I like it +3 Vote: I do not like it

I have just checked your solution using GNU C++14 after swapping the erase(it) and insert(*it) statements in both branches of the if-statement on s[i], and the solution was accepted 36144333. You may check the following faster GNU C++17 solution 36150970 based on vector< int > and vector< 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.