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

×

Confusion about TLE in a question.

https://www.codechef.com/problems/KPRIME This is the question i was attempting.Here is my code getting TLE https://www.codechef.com/viewsolution/16019853 .This is another solution by one @gargmehul10 https://www.codechef.com/viewsolution/15957624 getting AC with a time of 0.59 s. Even though my code uses lesser loops and we both followed the same concept, mine gets a TLE. Can someone please explain?

asked 31 Oct '17, 19:20

kriskhundu's gravatar image

3★kriskhundu
83
accept rate: 0%

edited 31 Oct '17, 19:23


Reason for TLE:

The code by @gargmehul10 executes the sieve only once inside main() for all the t test cases.

Your code executes the sieve t times for t test cases.

You are calling solve() which contains the sieve for all the t test cases.

Consider putting the sieve part in one function and call it just once before answering the test cases.

I hope this cleared your doubt.

All the best!

link

answered 31 Oct '17, 19:45

alfarhanzahedi's gravatar image

5★alfarhanzahedi
1836
accept rate: 33%

edited 31 Oct '17, 19:47

Thank you very much! Doubt cleared.

(31 Oct '17, 20:04) kriskhundu3★
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:

×2,718
×720
×31

question asked: 31 Oct '17, 19:20

question was seen: 348 times

last updated: 31 Oct '17, 19:47