I was trying to solve this problem and this is my code I thought it will pass but it gives TLE can anybody tell is it possible to optimize my code or my solution is completely wrong
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 146 |
| 3 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
I was trying to solve this problem and this is my code I thought it will pass but it gives TLE can anybody tell is it possible to optimize my code or my solution is completely wrong
| Название |
|---|



I don't know why it didn't work but I tried all the combinations which I can, then I got accepted:
this is the fixed code of yours:
https://cses.fi/paste/fb8283dd74e36c37103d53d/
Your code stores dp like dp[x][n] where x <= 1e6 and n <= 100, and when you get dp it first goes for 1e6 then goes to 100 which is slow, so you can just make first go 100 and then 1e6 by swaping this two states. Code
But what is the difference betweeen 1e6*100 and 100*1e6?
I think you can do some search what is the difference between dp[100][1e6] and dp[1e6][100] in c++, there are high educated people that explains better than me
Transitions between blocks are the most costly ones
Until today I thought they were the same thing. Thanks for the explanation
You can even get rid of the second dimension: here