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

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

https://codeforces.me/contest/455/submission/242903355

How my code got accepted ..without .the base case...

455A - Boredom

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

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

because when index becomes greater than the size of dp array the value of dp[index] is not -1.

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

    accessing dp[index] (index == size of dp) is an out-of-bounds access. C++ doesn't perform bounds checking by default, so accessing an index out of the vector's bounds will not necessarily result in an access violation error, but it leads to undefined behavior. Undefined behavior means that the program's behavior is unpredictable and it may lead to crashes, unexpected results, or other issues .

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

    it means that if we access dp[x] where x>dp.size(), then it will be not be equal to -1 that's why it get return there as dp[x]...but what is the surity that it will always give some negative garbage value..it can also give some random positive garbage value...which will result in wrong answer......because we are taking maximum of all the dp values as answer.......?? ??