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

×

TLE IN MGAME

Why am i getting a TLE in the second subtask in MGAME? my solution is https://www.codechef.com/viewsolution/22275286

asked 15 Jan, 17:29

sandy5858's gravatar image

3★sandy5858
01
accept rate: 0%

edited 15 Jan, 17:32


Have you tried using fast i/o? Here's a link which might help to implement it https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/

link

answered 15 Jan, 17:38

anupreetbhatia's gravatar image

3★anupreetbhatia
1
accept rate: 0%

ok .Thanks. It is really irritating to get a TLE when the logic is correct...:-(

(15 Jan, 17:42) sandy58583★

I was getting TLE too on using Scanner. What I did was that I used Buffered Reader for input. Buffered Reader is slightly faster than Scanner and I guess that made all the difference.

Here's my solution with TLE in second subtask : https://www.codechef.com/viewsolution/22297761

And here's my solution with AC : https://www.codechef.com/viewsolution/22297789

You can compare the two and fin that there is absolutely no change in the logic whatsoever. The only change you will notice is the Buffered Reader powered template.

link

answered 15 Jan, 17:41

sanidhya_98's gravatar image

4★sanidhya_98
1
accept rate: 0%

Here's my solution with TLE using Scanner and print the answer for each test case: https://www.codechef.com/viewsolution/22199684

I fixed this issue by collecting the answers in StringBuilder which takes 1.65 secs: https://www.codechef.com/viewsolution/22199707

So, the reason that you got TLE is most likely because of T, the number of test cases. (i.e, when T = 10^6). Anyway, using Buffered Reader instead of Scanner may work as well.

link

answered 15 Jan, 18:57

petch's gravatar image

4★petch
181
accept rate: 14%

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:

×729
×427
×112

question asked: 15 Jan, 17:29

question was seen: 138 times

last updated: 15 Jan, 18:57