Numinous's blog

By Numinous, history, 15 months ago, In English

So I was solving this problem Keen Tree Calculation from the recent contest, I was not able to figure out why I was getting a runtime error on Test 11. After struggling for half a day, I decided look in other people's submission and I found out a team which faced the similar issue. The fix for the problem was to make a copy of vector and then to iterate on it rather than iterating on the original. Here I have linked my submissions Accepted , RTE . It would be of great help, if someone can explain why the latter doesn't work.

Thanks

Update: The problem occurs because i am iterating over a vector whose size changes during the iteration and thus it may be reallocated.

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

»
15 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Please provide the line which you changed in your Accepted solution otherwise it's difficult to judge.

  • »
    »
    15 months ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    you can use the compare feature on codeforces while looking at submissions.

»
15 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Because garbage_lines is a vector which can be reallocated during LinesContainer::add

Don't iterate over container if it can be reallocated during loop (or use deque which elements have stable addresses)