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

Автор insurgentes, история, 3 года назад, По-английски

Hi all, I'm getting a runtime error while trying to submit my solution for 1588C - Игра с камнями which I cannot replicate on the custom invocation tab or locally in vscode. Any help debugging this would be very appreciated.

My code submission: 135533102

UPDATE: I was able to edit the logic for modifying the map to get A/C but unable to see what the issue was. New submission- 135560689

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

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

What do you think is container.rend().base()?

while (it != endings.rend())
            {
                if (it->first + offset > x)
                {
                    advance(it, 1);
                    endings.erase(it.base());
                }
                else
                {
                    break;
                }
            }
  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I think container.rend().base() == container.begin()

    I copied this piece of code from here btw, it explains the relationship between reverse iterator and base() https://stackoverflow.com/questions/1830158/how-to-call-erase-with-a-reverse-iterator

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

      If it = endings.rend(), then it.base() = endings.begin() — Yes

      And you are erasing endinds.begin(). What happens?

      it holding invalid invalid iterator and it != endgins.rend() is incorrect expression (left invalid iterator, right valid iterator, expression is UB [not sure undefined or unspecified])

      So you need do

      endings.erase((it + 1).base());
      ++it;
      

      instead of

      advance(it, 1);
      endings.erase(it.base());
      

      P.S. Sorry, of course increment is wrong, just erase increment of copy (135675180).

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

your submission link is for 1588C-game with stones, while you have tagged the question 1584C-Two Arrays as your question and i agree with you sometimes it is throwing RTE on custom invocation and sometime it is working fine.

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

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