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

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

UPD — seems the sieve function in my code caused some undefined behavior since it was getting out of bound, so I have got my answer. Thank you all who came forward to help. (I didn't even needed that function, it was left from the previous code, seems it was my unlucky day, atleast, got to learn something ;-;)

Why did I get runtime error for this code of mine in the competition?

link: https://codeforces.net/contest/1562/submission/127119400

While the same got accepted just after the competition

link: https://codeforces.net/contest/1562/submission/127129361

(exact same code)

PS- ;-; I am trying so hard to get better but these types of problem are so demotivating

MikeMirzayanov(edit-removed tag) please do help if possible ( I really don't want to be irritating ranting about my problem everywhere, but you see, this feels a big achievement to me, watching myself getting better everyday, and yes, ratings matter for me, rankings matter for me, it is kind of an adrenaline boost to me, so please help if possible ;-;)

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

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

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

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

I think the issue is legit, the exact same code got an AC that got an RTE previously in the contest. It'd be great if someone from headquarters could review this issue once.

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

Your sieve function contains undefined behaviour (your index goes out of bounds). It seems to me that you should change the line vi a(n,0); to vi a(n+1,0);

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

    Thank you for your insight.

    Will update that part, but atleast, in this code, this shouldn't have mattered, reason being my solution got accepted just after the contest, I believe so.

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

      When you have undefined behaviour in your code, all bets are off. You just got unlucky with bad RNG during the contest. I just submitted the same code and it passed 6 times and failed the 7th time. Btw. when you get a runtime error, it's probably almost always an out of bounds error, so look for that in the future.

      What's funny is that you could have just submitted the same code and probably passed the tests and this meme would actually come true hahaha

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

    And I mistakenly kept the sieve function, that was from the previous question ;-;

    But still that passed but this didn't, and for test case number 35 gave runtime error

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

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

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

If you compile with the -D _GLIBCXX_DEBUG and -D _GLIBCXX_DEBUG_PEDANTIC flags, your program will always crash when you run it locally and it gets an out of bounds error. The program will run slower, but it's really worth avoiding the chance of terrible undefined behavior

g++ A.cpp -Wall -Wextra -D _GLIBCXX_DEBUG -D _GLIBCXX_DEBUG_PEDANTIC