Learn › Competitive programming intro

Submitting, verdicts, and templates

How to compile locally, run samples, interpret judge verdicts, and keep a clean CP template. · 12 min read

Concept

A submission is a full program, not just an idea. Your local loop should be boring and repeatable: compile, run samples, test custom cases, then submit. When the verdict is not Accepted, use the verdict to narrow the failure instead of guessing wildly.

Local compile and run

A simple terminal loop for GNU C++ looks like this:

g++ -std=c++17 -O2 -Wall -Wextra -pedantic main.cpp -o main
./main < input.txt

On Windows PowerShell the executable is usually ./main.exe after compilation. Keep a small input.txt with the sample and a few custom cases so you can rerun quickly.

Common verdicts

  • AC: Accepted; output matched on all judge tests.
  • WA: Wrong Answer; logic, edge case, formatting, or overflow problem.
  • TLE: Time Limit Exceeded; asymptotic complexity or constant factors are too high.
  • MLE: Memory Limit Exceeded; arrays/tables/graphs are too large.
  • RE: Runtime Error; out-of-bounds, division by zero, recursion overflow, invalid access.
  • CE: Compilation Error; syntax, missing include, wrong language version, or unsupported feature.

Debugging without hidden tests

When you cannot see the failing input, build your own. Generate tiny cases and compare your optimized solution against a brute force solution. This is called stress testing, and it is one of the fastest ways to catch hidden-case bugs.

// Sketch: compare fast(a) with brute(a) on many small random arrays.
for (int seed = 1; seed <= 10000; seed++) {
    vector<int> a = makeSmallRandomCase(seed);
    if (fast(a) != brute(a)) {
        cerr << "Mismatch on seed " << seed << '\n';
        print(a);
        break;
    }
}

A clean beginner template

Keep the template small. A template should remove ceremony, not hide your solution.

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (ll &x : a) cin >> x;

    // Write the actual idea here.
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int tc = 1;
    // cin >> tc; // uncomment when the statement has multiple test cases
    while (tc--) solve();
    return 0;
}

Habits that prevent common failures

  • Use long long for sums, products, counts, and distances unless you are sure int is enough.
  • Print exactly what the statement asks: spaces, newlines, case labels.
  • Reset per-test-case data inside solve().
  • Avoid global arrays sized from guesses; size them from constraints.
  • Assert invariants locally, then remove noisy debug output before submitting.
  • For modular arithmetic, normalize negative values with (x % MOD + MOD) % MOD.

Practice: Two Sum (Easy) — Find the two indices whose values add up to a target.

Practice: Valid Parentheses (Easy) — Are the brackets balanced and correctly nested?

Previous: First problem walkthroughs · Next: Big-O in one sitting

More in Competitive programming intro