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

×

Beginner Need Help

I have just started solving problems in code chef.But, many of my submissions show wrong answer,run time error and many a times time limit exceeded. I check my program on other soft wares and it works perfectly there. When i see other submissions many of them use int long long. Is it necessary.And what are the other precaution i should take before submitting. Please help.

asked 12 Apr '15, 12:38

ajankit2304's gravatar image

4★ajankit2304
132
accept rate: 0%

retagged 12 Apr '15, 18:27

arun_as's gravatar image

1★arun_as
7413618


If you are a beginner, here are some tips you should follow:

1) Check the constraints properly. If you are given a variable n whose value is upto 10^7 and you have to find the square of the number, then the square will be upto 10^14 which can not be stored in int. U need long long int. Similarly for floating point numbers, when precision upto 10^-6 is required, u need double data type. If you are not yet comfortable with the data types, use long long int and double for all variables.

2) To avoid compilation error, you need to follow the standards in a programming language. Simple rule is, don't use conio.h header file, getch(), clrscr() etc.

3) If you use an integer array of size 10^6, it is okay, but for 10^7 or 10^9 and so, it will take too much memory causing SIGSEGV error. Stick to 10^6 or if u need, upto 4* 10^6. This is safe size of an array. Also take a good look at the constraints. If you need an array of upto 10^9 (say), then be sure your approach is wrong and there are other simpler approaches for the same program. Also, see if a condition in your constraints is leading to division by zero or any other such undefined behaviours.

4) For TLE, you need better algorithm. When you are struck at a problem with TLE, google for a better algorithm for your same approach.

link

answered 12 Apr '15, 15:29

dragonemperor's gravatar image

3★dragonemperor
89321134
accept rate: 10%

Please be sure that you dont write output inncorrectly (eg "YES" instead of "Yes"), thats annoying to debug.

link

answered 13 Apr '15, 10:27

ashish1729's gravatar image

3★ashish1729
1535
accept rate: 10%

dragonemperor said a lot of good things in his comment above; however, I have few remarks about it.

Yes, in most cases when you are beginner and you want to use an array of size 1e8 or something like that - it is because your idea is bad; but ML at Codechef is big, so often it is OK to use such arrays (even if you can get rid of them in most cases).

You may calculate how much memory your program needs, if it is few hundreds of megabytes - that is not too much for Codechef (but in 95% of cases you may solve problem with less amount of memory used).

And for TL, either your solution is completely wrong, or it is implemented in a slow way; you may try to run it on some sort of "worst case" and check how long it works. If your program runs 1 minute when TL is 1 second - you'd better look for other algorithm; but if it works 1.5 seconds when TL is 1 second - often you can optimize your code to make it run fast enough. Precompute some stuff, make some constant optimizations, add few breaks and so on.

link

answered 13 Apr '15, 14:58

lebron's gravatar image

7★lebron
3.3k317
accept rate: 24%

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:

×1,901
×1,470
×421

question asked: 12 Apr '15, 12:38

question was seen: 949 times

last updated: 13 Apr '15, 14:58