shankysodhi's blog

By shankysodhi, 13 years ago, In English

Hi everybody .

I participated in the CodeChef's June Cook Off challenge ... or should i say i tried to participate in it . The reason being ,i got stuck at the very first problem . Every time i submit the solution i got TLE. The frustration continued for about 2 hrs with no luck what so ever. I asked the problem setters/testers there to please explain what was the problem but got no response (even after the contest was over). So i was hoping u guys could help me . Its not much of a problem (that was the frustrating part).

The problem is available at :

http://www.codechef.com/problems/KNIGHTMV/

I have my solutions as : ( in the order .... lastest solution to the oldest solution )

http://www.codechef.com/viewsolution/578839
http://www.codechef.com/viewsolution/578334
http://www.codechef.com/viewsolution/578234
http://www.codechef.com/viewsolution/578111

I am no expert in programming (as reflected in the color of my handle) ... so i guess the error(if any) will be minor.

If you got time ....please go through it .. will appreciate any help .... Thanks. :)

  • Vote: I like it
  • +6
  • Vote: I do not like it

13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
Try using PrintWriter
http://pastie.org/2092670
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    Does it make any difference . It wasnt mentioned anywhere in the problem . Plus i always use System.out.println. Never had a problem before .
13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
@cerealguy/Scorpy : Amazing the same solution works with printwriter with the execution time of 0.55s . But i am still blank . What difference does it make, considering the fact that even printwriter uses System.out and the instance of printwriter uses .println. And even if there is difference , could it have eaten up more than .45s .... i mean thats roughly equal to the time for the execution of the algo(using printwriter) ???
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    Actually, printing and reading input is a major part of the time taken in this question. The calculations and verification is actually very very fast.
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    PrintWriter uses buffering.
    Writing 50000 lines without buffering is not a good idea, especially on CodeChef and Anton Lunyov's contests which are known for impossible java time limits.