Beta
Write the editorial, not the boilerplate.
CP Lang is a language for competitive programming. It compiles to one readable C++17 file you submit anywhere.
Press Run (Ctrl+Enter).
The limits from the statement are the types. Change 90 to 900 in the input and run: the run stops and names the value.
Compare with the C++ (15 lines against 3)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
assert(1 <= n && n <= 200000);
vector<int> a(n);
long long sum = 0;
for (int& x : a) {
cin >> x;
assert(1 <= x && x <= 100);
sum += x;
}
cout << sum << "\n";
}A standard library built for contests
Segment trees, shortest paths, union-find and modular arithmetic are one line each. Browse the library (36 modules)
Press Run (Ctrl+Enter).
Point updates and range minimum. You give SegTree the operation; fold takes the range as the statement writes it.
Find the bug in seconds
This solution has a bug. The brute force and the generator live in the same file, so one command finds a failing input, shrinks it, and names the first value that differs. Then you step through both runs side by side.
Press Run (Ctrl+Enter).
Run it on the shrunk case: it prints 1, the answer is 2.
$ cpl stress buy.cp --cases 200 --trace --explain
brute: buy.cp (`slow`) checker: none
FAIL on case 3 (seed 3): WA
shrunk from 5 numbers to 4:
3
1 2 3
expected:
2
got:
1
first difference at line 1, token 1: expected `2`, got `1`
first differing value: `best`, its 3rd value
solution never gives `best` a 3rd value
brute best = 2 at line 22
trace buy.tests/stress-3.trace.html
saved buy.tests/stress-3.in
Real output from today's compiler, regenerated on every build.
Whole olympiad solutions
Complete solutions to real olympiad problems, next to more of the syntax they rely on. Each carries its status: the ones the compiler does not run yet have no Run button.
let (n, m, q) = read<(1..=2e5, 1..=2e5, 1..=2e5)>()
domain V = 1..=n
domain Street = 1..=m
let street = read<[Street](V, V)>()
let odd = street.ring.minimal(
undoing(ParityDsu<V>(), add: (mut d, (u, v)) => d.unite(u, v)),
ok: u => not u.state.consistent,
)
for closed in read<[q]Range<Street>>():
let shortest = odd[street.ring.prev(closed.l)]
print(yes(shortest.is_some_and(w => w.len <= m - closed.len)))BOI 2020 Joker, the whole solution. The editorial needs divide and conquer over a rollback DSU; here minimal finds the shortest windows with an odd cycle and undoing lets the DSU drop from the front.
let (n, m, q) = read<(1..=2e5, 1..=2e5, 1..=2e5)>()
domain V = 1..=n
domain Street = 1..=m
let street = read<[Street](V, V)>()
var deg: [V]Int = 0
for (u, v) in street:
deg[u] += 1
deg[v] += 1
for closed in read<[q]Range<Street>>():
print(deg[street[closed.first!].0], closed.len)The statement's format and limits are written once. They drive parsing, validation and the width of every value.