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

Автор 0gnjen1, история, 4 месяца назад, По-английски

Today I spent a few hours solving problem C from the Codeforces Round 917. Most of the time was spent on me not understanding why my code won't work even after spending a lot of time trying to find the bug. It turned out to be a really weird 'bug' which I really can't understand. I managed to fix the code and get AC in the end but it was basically on accident.

I will put comments next to the lines of code that I changed so you can find your way around my messy code a little more easily.

Submission for code 1 right here

Code with the 'bug'

Submission for code 2 right here

Code without the 'bug'

I know using a vector was redundant but I don't see a single reason why it gives a wrong answer? I really hope someone with more knowledge will be able to help me understand why this was happening so I can avoid a similar bug in the future :D

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

»
4 месяца назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

possible.push_back(d/2); in the first solution is incorrect. In general, you can't always reach $$$\left\lfloor d/2\right\rfloor$$$ points, for example in this test:

1
1 1 2
2
1

The correct value would be $$$\left\lfloor (d-1)/2\right\rfloor$$$. But in the second solution, this line doesn't exist, or in other words, this line of code doesn't help the solution. You can just remove it and the solution will be correct.

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

    Wow, I can't believe I managed to oversee that. Thank you a lot man :D