Even after knowing a language concept’s and syntax, we find it difficult to submit questions online. Here are some guidelines every beginner must see before jumping into the world of competitive coding.
Each problem is divided into the following sections where each section provide important information about the problem.
This section provides the baisc information about the problem and explains WHAT
you need to do in the problem. Read this section carefully as basic details of the problem is provided under this section.
Input format specifies that how our judge will provide the input to the code that you have submitted. It specifies in which order you need to take the input for different variables. Output format specifies that what you need to print and in which order you need to print.
There are some basic mistakes that is made by most of the beginners while taking the input or printing the output. Consider a problem in which a user needs to take a number as input and print it's factorial as output.
Following are the two ways of taking the input for this problem.
|printf("Enter the number :");
Similarly following are the two ways of printing the output for this problem.
Remember anything you print extra, even your answer is correct, that is not specified in the output section will directly result to WRONG ANSWER.
|printf("Factorial of the given number is %d\n", ans);
Other important thing is that you need to print the output in specified format. Consider there are multiple test cases and for each test case problem specifies to print the output in new line than
|1 2 6 24
This section specifies the range of variables that will be provided during input. These constraints help you to decide that what should be the data type of the variables or the what should be the size of array that you are going to use in your programs.
You may also analyze by looking at the constraints that whether the complexity of your code will pass the given time or memory limit as specified in the problem.
This section specifies that maximum time and memory limit that will be provided to your solution. Your solution must run in the given limits or else will result into some kind of error as explained below.
After going through the above sections of the problem, now it is your turn to think and code the solution. After submitting your solution, you will see one of the following results.
This means that your code ran perfectly on our test cases within given time and memory limit and output of your code matched perfectly with our judge's output without any error.
This means that the output given by your program did not match our judge's output for the given input (or did not fulfill the conditions in case multiple solutions were possible). This is the most frequently occurring bug that you will face and getting rid of it can be a pain.
- First of all you must check that your program gives correct output for the sample test cases, exactly satisfying the output format. Try corner test cases.
- Read your code completely once before testing. This way you will be able to remove any obvious bugs.
- Check for incorrect variable initializations / uncleared memory, etc. These errors can also occur when you copy paste code.
- In case you keep getting wrong answer even after you have tried to find the bug in your program you must rethink upon you algorithms and prove it if you haven’t done so.If you find bug in your algorithm start working on new algorithm.
This error occurs when there is syntax error in your code.
Time Limit Exceeded
This means that your code is taking more time to run than the time provided by the problem setter.
- You program failed to generate all output within given time limit.
- Input Files are not randomly generated, they are made such that slow codes do not pass the given time limit.
- Always think of worst cases before you start coding. Always try to avoid TLE.
- Sometimes a little optimizations are required and sometimes you really need a totally new and efficient algorithm (this you will learn with time).
- So whenever you are in doubt that your code will pass or not, most of the time it won’t pass .
- Again do proper order analysis of your solution .
Note :- A loop of 108
instructions takes approximately 1 sec to run.
Memory Limit Exceeded
This means that you code is taking more memory to run than the default memory size that is allocated to a program. You need not bother unless you are using insanely
large amount of memory.
Note :- Try to keep the size of array atmost 107
Run Time Error / Segmentation Fault
There can be many types of Runtime Exceptions. You cannot know anything more specific. Note that some errors could lead onto other errors, so even if you are getting one particular message, you should check each one separately.
Following are the some of the reasons that why you get this error.
- You declared an array of smaller size than required or you are trying to access negative indices.
- Make sure you aren't using variables that haven't been initialised. These may be set to 0 on your computer, but aren't guaranteed to be on the judge.
- Dividing by Zero or taking modulo with zero.
- Sometime you may get NZEC error. NZEC stands for Non Zero Exit Code. For C users, this will be generated if your main method does not have a return 0; statement. Other languages like Java/C++ could generate this error if they throw an exception.
- Other type of frequent error is SIGBART. SIGABRT errors are caused by your program aborting due to a fatal error. In C++, this is normally due to an assert statement in C++ not returning true, but some STL elements can generate this if they try to store too much memory.
This error occurs when our judge fails to evaluate your code correctly. If you face this error than try submitting your solution again. If you keep on facing this error regularly than contact the site administrator and report this error.