why my code is giving runtime error in CSES dp-7th problem (book shop)??.Please help me. link to code- https://cses.fi/paste/31a10089630000cd20d9fe/
# | User | Rating |
---|---|---|
1 | tourist | 3947 |
2 | jiangly | 3734 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3612 |
7 | ecnerwala | 3581 |
8 | Geothermal | 3569 |
8 | cnnfls_csy | 3569 |
10 | ksun48 | 3479 |
# | User | Contrib. |
---|---|---|
1 | awoo | 162 |
2 | maomao90 | 160 |
3 | nor | 156 |
4 | adamant | 155 |
4 | atcoder_official | 155 |
4 | -is-this-fft- | 155 |
4 | cry | 155 |
8 | maroonrk | 153 |
9 | SecondThread | 147 |
10 | Petr | 146 |
why my code is giving runtime error in CSES dp-7th problem (book shop)??.Please help me. link to code- https://cses.fi/paste/31a10089630000cd20d9fe/
Name |
---|
Use int instead of long long. Using long long is causing memory limit to exceed causing RE.
You are exceeding the memory limit. If you look at your submission, you can see that you use more than the memory limit for that problem, which is 512MB.
In this case, this is easy to fix: your outer loop is over $$$i$$$, and at index $$$i$$$, you only access $$$DP[i]$$$ and $$$DP[i-1]$$$. Thus it is enough to maintain a $$$2 \times (x+1)$$$ array $$$DP'$$$, where at step $$$i$$$ you have $$$DP'[0] = DP[i - 1]$$$ and $$$DP'[1] = DP[i]$$$. When incrementing $$$i$$$ you can set $$$DP'[0][j] \leftarrow DP'[1][j]$$$.