insurgentes's blog

By insurgentes, history, 2 years ago, In English

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

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

| Write comment?
»
2 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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;
                }
            }
  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      2 years ago, # ^ |
      Rev. 3   Vote: I like it +5 Vote: I do not like it

      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).

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks! fixed. I was able to modify the solution to get A/C, but still unsure about the issue. 135560689

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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