Skip to content

Guide

How online judges decide a verdict: AC, WA, TLE, MLE, RE

By Vishnu KumarPublished 7 min read

You submit, wait a second, and get two letters back. This guide explains what happens between the submit button and the verdict on a typical judge, what each verdict means precisely, and the specific, common reasons a solution that worked on your laptop fails on the server.

What happens when you submit

A judge does the same few steps for every submission, whether it is a contest site, an interview platform or ls-judge, which powers our own tools:

  • Compile, if the language is compiled, with fixed flags and a time and memory limit on the compiler itself.
  • For each test case, start a fresh, isolated process, feed the test's input on standard input, and collect standard output and standard error.
  • Enforce limits while it runs: CPU or wall time, memory, output size and process count.
  • When it exits, compare the output with the expected answer using the problem's checker.
  • Report a verdict per test. Most judges stop at the first failure and show you that test's number; some run every test and report each.

Each verdict below corresponds to the step where things went wrong.

The verdicts

Common verdicts and the step that produces them
VerdictMeansProduced when
AC, AcceptedOutput matched on every testAll tests pass the checker
WA, Wrong AnswerThe program finished but printed the wrong thingChecker rejects the output
TLE, Time Limit ExceededThe program did not finish in timeKilled at the time limit
MLE, Memory Limit ExceededThe program used more memory than allowedKilled by the memory limit
RE, Runtime ErrorThe program crashed or exited non-zeroSignal or non-zero exit status
CE, Compile ErrorThe source did not compileCompiler failed or timed out
OLE, Output Limit ExceededThe program printed far too muchOutput passed the cap
PE, Presentation ErrorRight answer, wrong whitespace (older judges only)Exact checker that distinguishes whitespace

Verdicts are reported for the first failing test on most judges, so a WA on test 7 says nothing about tests 8 onward. Fix the failure and resubmit; the next run may stop somewhere else.

How output is compared

The checker decides what "matches" means, and it is the most misunderstood part of judging. There are three common modes:

  • Exact: byte-for-byte equality, sometimes ignoring a trailing newline. Rare today because it punishes harmless whitespace.
  • Token: split both outputs on whitespace and compare the tokens. 1 2 3 matches 1\n2\n3. This is the default on most modern judges, including ls-judge's TOKEN mode.
  • Floating point: compare numbers within a tolerance, usually an absolute or relative error of 1e-6 or 1e-9. Printing 0.333333 against an expected 0.3333333333 passes at 1e-6 and fails under exact comparison.

Problems with many valid answers (any shortest path, any valid ordering) use a special checker program that reads the input and your output and verifies the answer's properties instead of comparing text. If a problem says "print any", expect a special checker; if it does not, assume token comparison against one exact answer.

Wrong Answer: the usual suspects

  • Integer overflow. A sum of 10⁵ values up to 10⁹ is 10¹⁴, far beyond a 32-bit int. Use long long in C++, long in Java; Python integers never overflow.
  • Reading input differently from how it is given: several test cases in one file, a count on the first line, or input that ends without a trailing newline.
  • Edge cases the samples do not show: n = 1, an empty string, all-equal elements, negative numbers, the maximum size.
  • Floating point printed with too few digits. Print with fixed precision, for example printf("%.9f\n", x), unless the problem says otherwise.
  • Leftover debug output. Anything written to stdout is part of your answer; write debugging to stderr.
  • Uninitialised variables in C and C++, which happen to be zero on your machine and are not on the judge.

Time Limit Exceeded: it is usually the algorithm

Judges size tests so that the intended algorithm finishes comfortably and the naive one does not. A rule of thumb: a modern judge executes roughly 10⁸ simple operations per second in C++, fewer in Java and far fewer in Python. Compare your complexity with the input limits before optimising anything else.

Largest n that usually fits in about one second (C++)
ComplexityComfortable n
O(n!)about 10
O(2ⁿ)about 20 to 25
O(n³)about 500
O(n²)about 5,000 to 10,000
O(n log n)about 10⁶
O(n)about 10⁷ to 10⁸

When the algorithm is right and it still times out, input and output speed is the next suspect. Reading 10⁶ numbers with unbuffered I/O can take longer than the algorithm itself:

// C++: untie cin from cout and stop syncing with C stdio
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// and print with '\n', not std::endl, which flushes every line
# Python: read everything at once instead of calling input() per line
import sys
data = sys.stdin.buffer.read().split()
n = int(data[0])
values = list(map(int, data[1:1 + n]))
sys.stdout.write("\n".join(map(str, answers)) + "\n")
// Java: Scanner is slow for large inputs; use a buffered reader and tokenizer
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());

A program that waits for input that never comes also ends as TLE, because it blocks until the wall-time limit. That happens when the code expects one more line than the test provides.

Memory Limit Exceeded and Runtime Error

MLE means the kernel stopped the program for using more memory than the limit, typically 256 MB. The fix is almost always a data structure: an n by n matrix for n = 10⁵ is 10¹⁰ cells, which no limit will allow. Note that memory counts everything the process maps, so a Java program pays for its virtual machine before the first line of your code runs, and judges often give Java extra headroom for that reason.

Runtime Error covers any abnormal exit. The exit signal usually tells you which kind:

Reading a runtime error from its signal (Linux)
Signal / exitTypical cause
SIGSEGV (exit 139)Out-of-bounds array access, null pointer, or a stack overflow from deep recursion
SIGFPE (exit 136)Integer division or modulo by zero
SIGABRT (exit 134)A failed assertion, or an uncaught C++ exception such as std::bad_alloc
Non-zero exit in Java or PythonAn uncaught exception: IndexOutOfBounds, NullPointer, RecursionError, ValueError on bad parsing

Deep recursion deserves a special mention. A depth-first search over a 10⁵-node path recurses 10⁵ times. Python's default recursion limit is 1,000, so raise it with sys.setrecursionlimit and expect the C stack to become the next limit, or convert the search to an explicit stack. Java's default thread stack is small too; run the solution in a new Thread(null, task, "main", 1 << 26) to get more.

One distinction worth knowing: a judge that only looks at the exit signal cannot tell an out-of-memory kill from any other SIGKILL. Good judges read the memory controller's event counters to report MLE correctly instead of a generic RE.

Why it passed on my machine

  • Different compiler or flags: the judge may use a different standard version, no -O2, or treat warnings differently. Check the language list for the exact compiler and version.
  • Undefined behaviour in C and C++ that happens to work locally (reading past an array, uninitialised memory) and does not on the judge.
  • Your local tests were the samples. The hidden tests include maximum sizes and edge cases.
  • Local stack size is larger: many desktop shells allow 8 MB or unlimited stack, and a judge's sandbox may allow less.
  • Timing: the judge's CPU may be slower per core than your laptop, and time limits are set by running the reference solution on the judge's own hardware, not yours.

The fastest way to debug is to write a brute-force solution that is obviously correct, generate small random inputs, and compare the two programs' outputs until they disagree. That finds the WA test the judge will not show you.

Try it yourself

Omni Compiler lets you define your own test cases and returns these verdicts per test on a phone, and the practice problems on Code Sprout are judged the same way against hidden tests. If you are building a judge rather than using one, read how to run untrusted code safely next.