Yasuho_Hirose's blog

By Yasuho_Hirose, history, 4 months ago, In English

here is my solution: https://codeforces.com/contest/1624/submission/144304382 for this problem: https://codeforces.com/contest/1624/problem/E I think time complexity of this solution is O(n*m) is small enough, but why this still give TLE? Thanks you for read my shi* blog.

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

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

probably because of using memset for every testcase.

memset(t2,0,sizeof(t2));

with 10000 testcases and t2 of the size 1000, this TLEs

  • »
    »
    4 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    i think this is not problem, because time complexity of memset is o(n), and t1, t2 just 100 and 1000 elements. I think this give tle when assign dp[i-2] or dp[i-3] to dp[i], i got accepted now. Anw, thank you so much.

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Oh

I often suffer from this problem also.

The reason of you getting TLE is because you code's runtime is longer than the time limit (i.e. 3 seconds)

What you should do is to code a code with a shorter runtime which is shorter than the time limit.

But then how do you know if the new code have a runtime shorter than the time limit or not?

You can then simply submit your code to the online judge (i.e. codeforces) to the corresponding question.

If your code have a runtime shorter than the time limit, codeforces will return a green, “Accepted" word.

but then if your code have a longer runtime than the time limit, codeforce will return a blue,"Time Limit Exceeded on Test XX" where XX is a number.

Hope this will help.