×

# Beginner Need Help

 1 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 13●2 accept rate: 0% 1★arun_as 741●3●6●18

 1 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. answered 12 Apr '15, 15:29 893●2●11●34 accept rate: 10%
 0 Please be sure that you dont write output inncorrectly (eg "YES" instead of "Yes"), thats annoying to debug. answered 13 Apr '15, 10:27 153●5 accept rate: 10%
 0 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. answered 13 Apr '15, 14:58 7★lebron 3.3k●3●17 accept rate: 24%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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