You are not logged in. Please login at www.codechef.com to post your questions!

×

Why am I getting TLE?

Can anyone tell me why I am getting TLE in http://www.codechef.com/viewsolution/4855478 ?

asked 19 Sep '14, 19:49

jsk1_s's gravatar image

2★jsk1_s
01
accept rate: 0%


  • In your code, 'b' represents 'A' as mentioned in the problem. A < 10^9.
  • And your solution has the loop while(k--){}. Hence your solution will take approximately A steps, or in easier way, the number of steps of your problem is of the order A. Hence your code is an O(A) solution. For algorithm analysis: http://www.geeksforgeeks.org/analysis-of-algorithms-set-1-asymptotic-analysis/
  • Now, we all know the computation power of a processor is also limited. Assume 1 sec ~ 10^8 operations per second . (for SPOJ old server it is 4*10^6). Keep this in mind while solving any problem.

  • So if A < 10^6 then your solution will pass, but here A<10^9, hence it is giving 'Time Limit Exceeded'. Try to come with a optimal solution :)

  • Hint: This problem has a O(k) solution and k, according to problem statement is < 100 :D
link

answered 19 Sep '14, 20:42

ketanhwr's gravatar image

6★ketanhwr
1.9k31844
accept rate: 15%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×717
×14

question asked: 19 Sep '14, 19:49

question was seen: 699 times

last updated: 19 Sep '14, 20:42