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

×

MGAME timeout

Can you please explain why my solution timed out for the second subtask? I used the same method described in the editorial:

https://www.codechef.com/viewsolution/22454513

I even submitted a DP solution with precalculated values:

https://www.codechef.com/viewsolution/22467759

This was a contest solution, it affects my score.

Edit:

I have tested I/O speed on the Enormous Input Test problem:

https://www.codechef.com/viewsolution/22491210

https://www.codechef.com/viewsolution/22491207

Both of them were accepted, the Console.WriteLine(count) version is little bit faster. How was I supposed to know my output is not fast enough?

asked 14 Jan, 20:36

krark's gravatar image

3★krark
21
accept rate: 0%

edited 15 Jan, 15:31


Did you try to use BufferedReader?

For details, see https://discuss.codechef.com/questions/55818/faster-input-in-java

link

answered 15 Jan, 01:43

oleg_b's gravatar image

7★oleg_b
3195
accept rate: 16%

It's C#, not Java. I'm using the standard Console.ReadLine() as always.

(15 Jan, 01:53) krark3★

Apologies for the language mix-up.

The issue is definitely with the I/O speed.

If you change your line Console.WriteLine(count); to Console.WriteLine("{0}", count); then you get an AC.

link

answered 15 Jan, 02:26

oleg_b's gravatar image

7★oleg_b
3195
accept rate: 16%

Thanks a lot! I should've tested my I/O speed. It's really annoying to lose points because of that.

(15 Jan, 14:18) krark3★

Once the input/output size reaches 10^5, the I/O should always be a concern, and it may take non-trivial amount of time just to read the problem data and write the answers. It's just one thing to keep in mind always.

(15 Jan, 16:21) oleg_b7★

Also, printing each answer one by one is not a good idea for this problem, unfortunately. If T = 10^6, your code prints the answer 10^6 times, which may lead to TLE. I also had this issue and fixed it by collecting them in StringBuilder. See here: https://www.codechef.com/viewsolution/22199707 It somehow works in 1.65 sec. By the way, I/O speed is another concern as well.

link

answered 15 Jan, 19:22

petch's gravatar image

4★petch
181
accept rate: 14%

edited 15 Jan, 20:07

I can't view your solution for some reason, but yes, it makes sense to output like that. But it's not necessary, if you just want to gain 100 points.

(15 Jan, 19:50) krark3★

Already fixed the link. Yeah, I understand that. I got this issue in some long contest before and it is so annoying. Using Buffered Reader and do not print too often are always the best options.

(15 Jan, 20:12) petch4★

plz anyone explain the logic i cannot understand editorial

link

answered 15 Jan, 20:18

karun369's gravatar image

2★karun369
11
accept rate: 0%

You need to understand how modulo arithmetic works. Counting the possibilities is just a matter of combinatorics.

(15 Jan, 20:26) krark3★

plz anyone explain the logic i cannot understand editorial

link

answered 15 Jan, 20:18

karun369's gravatar image

2★karun369
11
accept rate: 0%

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:

×340
×112
×44
×30

question asked: 14 Jan, 20:36

question was seen: 323 times

last updated: 15 Jan, 20:26