CSES - E4590 2017 1 - Technical guide

Solving tasks

In each task you must write a program which reads standard input and writes to standard output. CSES evaluates each submission by testing it with multiple inputs.

The program will be executed in an isolated environment, which means that using temporary files or internet connection is not possible. The execution will be terminated if it exceeds time or memory limits.

Error cases

For each submission CSES will tell you if your submission has passed all tests. If that's not the case it will tell you the reason. The reason is always one of the following:

COMPILE ERROR: Compilation of the submission failed. You can get more information from the output of the compiler.

OUTPUT LIMIT EXCEEDED: The program produced too much output.

TIME LIMIT EXCEEDED: The execution of the program took too long.

RUNTIME ERROR: The program returned a non-zero exit code. This may be due to memory overuse or unhandled exception.

WRONG ANSWER: The program produced wrong answer.

The error message is from the first failed test case. If the program failed multiple test cases, only the first error will be shown.

Programming languages

Allowed programming languages are C++, Java, Python2, Python3 and Haskell. Each task is possible to solve with at least C++. Please notice that you may need to use some optimisations for input and output handling.

Java

CSES uses OpenJDK 1.8.0_91 (Java 8).

Name your code file according to the java rules. The file containing class called Main should be upload as Main.java. The code must not be in any packages or the compilation will fail.

Java's default Scanner and System.out.println may be too slow for input and output. The runtime environment contains a faster class for handling input and output called IO. It doesn't need to be imported as it resides in the same directory as the program. You can use IO class as follows:

public class Solution {
public static void main(String[] args) {
	IO io = new IO();
	
	String a = io.next(); // Reads the next string separated by spaces.
	int b = io.nextInt(); // Reads the next int separated by spaces.
	long c = io.nextLong(); // Reads the next long separated by spaces.
	double d = io.nextDouble(); // Reads the next double separated by spaces.
	
	// Works like System.out.println.
	io.println("Input was " + a + " " + b + " " + c + " " + d);
	
	io.close(); // MUST BE CALLED IN THE END, otherwise some of the output may be missing
}
}

You can find IO class here: IO.java.

C++

The C++ compiler used by CSES is g++ 4.8.4. Used flags are -std=c++0x -O2 -Wall.

The default cin and cout may be too slow as default but they can be made much faster by removing synchronization with C's stdio library. This can be done by adding line

cin.sync_with_stdio(false);

in the begin of main function:

#include <iostream>

using namespace std;

int main() {
	cin.sync_with_stdio(false);
	
	// solve the task here
}