Help | CodeChef

Help

The CodeChef System

Example

Technical Issues related to C/C++

Technical issues related to other OS system users

The CodeChef System

Submitted solutions are automatically compiled and run under Linux test system. You must keep strictly the input output specification. In particular your program must not printout any additional messages like 'input the number please', which are not specified in the problem formulation.

Compilers

Submitted solutions are compiled according to the user selection made during the submission process. For example:

  • gcc 4.0.0-8 (with standard library) for C language.
  • g++ 4.0.0-8 (with Standard Template Library) for C++ language.
  • fpc 2.0.4 (with standard `library end Delphi extension for FreePascal) for Pascal language.
  • j2se jdk 5.0 with standard library (excluding some multimedia, network and system interaction classes). Starting point for Java programs is public static void main (String[] a) method in Main class, which must be defined.
  • other compilers are accessible depending on chosen programming language: C 99strict, D, C#, Nemerle, Haskell, O'Caml, Prolog, Scheme, Lips, Clips, Icon, Whitespace, Fortran, Smalltalk, Ada95, Assembler (Nasm), Intercal, Php, Pike, Ruby, Perl, Brainf**k.

Source code length restriction

Source code length is restricted to 50 000 bytes in a one file. Additional restrictions might be provided for particular problems. Using external libraries or files is prohibited.

Execution time restriction

Execution time is restricted for each problem and for each test case separately. In each case restriction is not severer then 1s. Solutions are tested on equal PIII 733 MHZ processors.

Memory restriction

Accessible memory is at least 64MB.

Input Output

Program should read from standard input and write into standard output. There is no need to read all data first, compute them all and then print all output. It is recommended to read and write data as simultaneously. Technically, server redirects standard stream to files. You can test you programs in the same way at home.

Example

Task: write the program to find sum of two integers. Input two integers A and B. Output the sum of these integers.

Input example:

2 3

Output example:

5

Solution in C:

#include <stdio.h>;
int main() {
    int a, b; 
    scanf("%d %d", &a, &b); 
    printf("%d\n",a+b);
    return 0;
}


Solution in PASCAL:

program ex;
var a, b: integer;
begin
read(a,b);
writeln(a+b);
end.    


Solution in Java:

public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        java.io.BufferedReader r = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
        int a = Integer.parseInt(r.readLine()), b = Integer.parseInt(r.readLine());
        System.out.println(a + b);
    }
}

Solution submitting

To submit a solution choose problem from list of problems and press button 'Submit' at the top of the problem description. You can submit multiple solutions to each problem. Score for the problem is equal to the score of the best submitted solution.

To see the Statistic for problem choose problem from list of problems and press button 'All submissions' at the top of the problem description. To view the status, hover over the check box, cross or warning icon in the result column.

At present the following status codes are available:

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. The specific error codes are:
    • SIGSEGV(signal 11) - most common, 'segmentation fault';
    • SIGXFSZ (signal 25) - 'output limit exceeded';
    • SIGFPE (signal 8) - 'floating point error' - like division by zero, etc.;
    • SIGABRT (signal 6) - raised by the program itself; In C and C++ macro assert does it while fails, also C++ STL does it under some conditions;
    • NZEC (non-zero exit code) - helps telling crash from WA with interpreted languages;
    • other - there are other signals which can cause program to terminate, all remaining are shown as other.

Technical issues related to C/C++

Debugging at home

You could use symbolic constant ONLINE_JUDGE for debugging purpose. In C you can use:

#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

Input data are taken from input.txt, and output data are print to output.txt only outside the CodeChef system.

Technical issues related to other OS system users

New line encoding

Please consider it important that a new line characters can differ between Linux and other OS. It might be a cause of malicious bugs.

Using 64-bit number types

If you use a compiler in which a long long type does not exist (like MS VisualC++) then to assure proper compilation you can create a symbolic constant:

#define __int64 long long

In this case do not forget about proper output format:

%lld instead of %I64d in the case of using scanf/printf functions.