https://mirror.codeforces.com/contest/455/submission/242903355
How my code got accepted ..without .the base case...
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
https://mirror.codeforces.com/contest/455/submission/242903355
How my code got accepted ..without .the base case...
Name |
---|
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...