cp-book

ecnerwala's competitive programming library

View the Project on GitHub ecnerwala/cp-book

ecnerwala’s Competitive Programming Book

CI docs coverage

This is my library of reference code for competitive programming. The goal is to write generic, fast, and clean algorithm implementations for use in contests like CodeForces or ICPC.

The library lives in src/ as standalone headers (#include "fft.hpp", compiled with -I src). The library requires C++23 (the whole toolchain builds with -std=c++23, e.g. g++ >= 13). Browsable source, verification results, and coverage are hosted at https://ecnerwala.github.io/cp-book/.

Building and testing

cmake -B build && cmake --build build
ctest --test-dir build          # or ./build/tests

Bundling

Unfortunately, some files (e.g. full power series with all fft engines) are too long to fit in CF’s submission limit, so we need to bundle/minify them for submission.

scripts/bundle.py verify/convolution_mod.test.cpp > submission.cpp
scripts/bundle.py fft.hpp seg_tree.hpp     # bundle headers together
scripts/bundle.py --minify fft.hpp         # compiler-directed minification
scripts/bundle.py --all                    # pregenerate all headers

To run the bundler offline, first initialize the UV cache by running

uv sync --script scripts/bundle.py

Then, you can run

UV_OFFLINE=1 scripts/bundle.py ...
uv run --offline --script scripts/bundle.py ...

Upgrade the bundler’s lockfile with

uv lock --script scripts/bundle.py --upgrade

(Make sure to rerun the sync afterwards.)

Library Checker verification

verify/ holds Library Checker solutions, verified in CI with competitive-verifier.

# Run verification locally
uvx competitive-verifier oj-resolve --include src verify --exclude third_party \
    --config .competitive-verifier/config.toml > verify_files.json
uvx competitive-verifier verify --verify-json verify_files.json

Contest tooling

contest/ holds standalone tooling for contests: a problem-directory template (Makefile with sanitizers and precompiled headers), a layered .template instantiator (make_prob.py), and a Competitive Companion listener (download_prob.py). See contest/README.md. Contest programs are standalone; vendor book code in as needed (e.g. with scripts/bundle.py).

License and attribution

All code is written by me and CC0 licensed unless otherwise noted in the file. Inspiration is largely drawn from KACTL and other references.

Coverage

Coverage Exec / Excl / Total
Lines 63.5% 2866 / 0 / 4515
Functions 91.2% 1089 / 0 / 1194
Branches 72.3% 6911 / 0 / 9558
Full report

Library Files

combo_games/

fft/

fft/engines/

geometry/

graph/

Verification Files

verify/