My code library for competitive programming.
powered by competitive-verifier/competitive-verifier & Tiphereth-A/TINplate.
Documentation Site
·
Report Bug & Request Feature
·
Latest Release
·
Citation File
CP-lib is a header-only C++ code library designed for competitive programming with 450+ implementations of algorithms and data structures commonly used in competitive programming contests.
The repository solves several key problems for competitive programmers:
- Code Reusability: Provides well-tested, ready-to-use implementations of common algorithms and data structures
- Reliability: All implementations are automatically verified against problems from supported online judges (OJ) to ensure correctness
- Documentation: Generates printable PDF documents (notebooks) for offline reference during competitions
- Maintainability: Includes automated testing, linting, and verification workflows to keep the codebase reliable
- Verification: Automated testing on multiple online judges (Aizu, Library Checker, Yukicoder, etc.)
- Documentation: Supports PDF documentation generating for offline usage
- Test matrix: Generate multiple test variants from template.
Requirements:
- Compiler: GCC 13.0 or higher (GNU Compiler Collection)
- Python: Python 3.12 or higher (for management scripts)
- LaTeX: Required only if you want to generate PDF documentation
The project uses Python for management scripts. Install dependencies using uv.
Optional dependency groups:
- dev: Development tools (e.g.,
pycodestyle) - latex: LaTeX compiling dependencies (e.g.,
pygmentsfor syntax highlighting) - verify: Verification tools (
competitive-verifier) - bundle: Bundle codes by
oj-bundlefor submitting to OJs (online-judge-verify-helper)
For LaTeX compiling:
- Fonts: Run
make download-fontsto download required fonts (see.github/workflows/verify.yml) - inkscape for SVG files support
# Clone the repository
git clone -c core.symlinks=true git@github.com:Tiphereth-A/CP-lib.git
cd CP-lib
# Install Python dev dependencies
uv sync --frozen --group dev
uv run pre-commit install
# Install Python dependencies
uv sync --frozen
# Install verify group for using `oj-verify` if needed
uv sync --frozen --group verify
# Install bundle group for using `oj-bundle` if needed
# Warning: NEVER use `oj-verify` from `online-judge-verify-helper`
uv sync --frozen --group bundle
# Verify installation
python3 manager.py --help
# Run all C++ benchmarks locally (writes .cp-lib/benchmark_result.json)
python3 manager.py benchmarkThe manager.py script provides several commands for managing the repository, see python manager.py --help for details.
Q: How can I submit the code using headers of this repo to any OJ
A: Use oj-bundle to auto-expansion your code, it has been included in verify group of Python dependencies already.
You can also find a bundled button at any code pages of documentation site, click the button then you will get the expanded code.
Q: PDF generation is slow
A: This is normal for large LaTeX documents, the expected time used in PDF generation is about 6 minutes in GitHub Action.
- competitive-verifier: Automated verification system for competitive programming code
- TINplate: LaTeX template system for generating printable notebooks
- online-judge-verify-helper: Helper tools for OJ verification
This library is verified against problems from:
- Aizu Online Judge (AOJ)
- Library Checker (judge.yosupo.jp)
- Yukicoder
Thank you to all contributors who have helped improve this library! See the Contributors page.
This library is inspired by and builds upon the work of the competitive programming community, including:
- Various algorithm textbooks and resources
- Open-source competitive programming libraries
- Community discussions and improvements
See notebook.bib for details.
If you use this library in academic work, please cite it using the provided CITATION.bib file.