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

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

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!

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

»
7 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится
S0.erase(it);
S1.insert(*it);

You dereference an iterator directly after erasing it

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

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

    • »
      »
      »
      7 лет назад, # ^ |
      Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

      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.

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

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.

»
3 месяца назад, # |
  Проголосовать: нравится -7 Проголосовать: не нравится

Xin chào anh cuom1999, nhớ em trên LQDOJ ko