tasnidmahin's blog

By tasnidmahin, history, 3 weeks ago, In English,

Why getting TLE? Contest: Snackdown 19 Online round 1A Link: https://www.codechef.com/problems/CHEFADD

TLE Code: https://www.codechef.com/viewsolution/21159831 AC Code: https://www.codechef.com/viewsolution/21075438

These 2 codes are almost same but their verdicts are different.

 
 
 
 
  • Vote: I like it  
  • -7
  • Vote: I do not like it  

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

You could try to code the iterative dp, because it is way much faster. (I solved a lot of dp problems, in which the recursion gives TL, but the iterative solution passes)

»
3 weeks ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

There's a typo on line 55. It should be dp[i][aa][bb][r] != -1 instead of dp[i][aa][bb][r] =!-1. This typo makes it so that you don't actually memorize your answer. This modification makes your code pass in 0.07s.