MONASH COMPETITIVE PROGRAMMING



Online Judge Mechanism

Standard IO

Most of OJ (Online Judge) use following set up by default:

If you are fimilar with command line, the following code explains IO

./<my-program> < test.in > test.out

This tutorial can help you to understand these concepts.

File IO

Sometimes you have to use file IO, e.g. USACO, some Codeforces problems; which means the judge assumes your program will read/output from/to a specified file.

The minimum effort to adjust your code from standard IO to file IO is as follow (a+b problem).

1
2
3
4
5
6
7
8
import sys

sys.stdin = open('file.in', 'r')
sys.stdout = open('file.out', 'w')

# doing IO as normal 
a, b = map(int, input().split())
print (a+b)
1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;

int main() {
  freopen("file.in", "r", stdin);
  freopen("file.out", "w", stdout);
  // doing IO as normal
  cin >> a >> b;
  cout << a + b << endl;
  return 0;
}

Judge

Text-based comparison

OJ uses text-based comparison to judge your output in most of cases; which means your output will be compared with correct output by each character, thus any mismiatching will cause Wrong Answer (also see Common reasons for WA), for example

Some smart judge may discard extra whitespaces or newline characters, and gives you Accepted or Presentation Error.

Special Judge

When the answer is not unique (e.g. some constructive problems), special judge will be applied. There is another program to read your output and parse to data, then make judgement. If you didn’t follow the format as in the problem statement strictly, you will get Wrong Answer because of parsing failed.