Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

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

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

455A - Boredom

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

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

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

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится +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 .

  • »
    »
    8 месяцев назад, # ^ |
      Проголосовать: нравится +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.......?? ??

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

      It is not guaranteed to be 0 due to the garbage values in the vector, but it is a common scenario where the garbage value might often be interpreted as 0. Call it luck I guess.

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

        Ya that's what i am also thinking ..luckily it passed....because we can't be sure always that it will give negative garbage value...it is random...