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/
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 151 |
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/
Название |
---|
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]$$$.