https://mirror.codeforces.com/contest/455/submission/242903355
How my code got accepted ..without .the base case...
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
https://mirror.codeforces.com/contest/455/submission/242903355
How my code got accepted ..without .the base case...
Название |
---|
because when index becomes greater than the size of dp array the value of dp[index] is not -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 .
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.......?? ??
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.
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...