Блог пользователя Whitemuha

Автор Whitemuha, история, 3 часа назад, По-английски

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

  • Проголосовать: нравится
  • -4
  • Проголосовать: не нравится

»
3 часа назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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/

»
3 часа назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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