{"id":19462830,"url":"https://github.com/online-judge-tools/template-generator","last_synced_at":"2025-04-24T00:23:47.036Z","repository":{"id":49555573,"uuid":"78886441","full_name":"online-judge-tools/template-generator","owner":"online-judge-tools","description":"Analyze problems of competitive programming and automatically generate boilerplate","archived":false,"fork":false,"pushed_at":"2024-02-13T09:31:47.000Z","size":328,"stargazers_count":86,"open_issues_count":9,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T05:11:24.318Z","etag":null,"topics":["atcoder","automation","code-generation","codeforces","competitive-programming","cpp","programming-contests","python","templates","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/online-judge-tools.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-13T21:04:34.000Z","updated_at":"2025-03-24T02:01:38.000Z","dependencies_parsed_at":"2024-12-26T12:07:15.609Z","dependency_job_id":"05d99dcf-5d7c-4f39-9a9e-859e65d3d857","html_url":"https://github.com/online-judge-tools/template-generator","commit_stats":{"total_commits":253,"total_committers":4,"mean_commits":63.25,"dds":"0.015810276679841917","last_synced_commit":"df01cb45d5c7fc68fc9ae30e95eb2668f05fc3c6"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/online-judge-tools%2Ftemplate-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/online-judge-tools%2Ftemplate-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/online-judge-tools%2Ftemplate-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/online-judge-tools%2Ftemplate-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/online-judge-tools","download_url":"https://codeload.github.com/online-judge-tools/template-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250536486,"owners_count":21446743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atcoder","automation","code-generation","codeforces","competitive-programming","cpp","programming-contests","python","templates","testing"],"created_at":"2024-11-10T18:06:02.365Z","updated_at":"2025-04-24T00:23:46.982Z","avatar_url":"https://github.com/online-judge-tools.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# online-judge-tools/template-generator\n\n[![test](https://github.com/kmyk/online-judge-template-generator/workflows/test/badge.svg)](https://github.com/kmyk/online-judge-template-generator/actions)\n[![Documentation Status](https://readthedocs.org/projects/online-judge-template-generator/badge/)](https://online-judge-template-generator.readthedocs.io/en/latest/)\n[![PyPI](https://img.shields.io/pypi/v/online-judge-template-generator)](https://pypi.org/project/online-judge-template-generator/)\n[![LICENSE](https://img.shields.io/pypi/l/online-judge-template-generator.svg)](https://github.com/kmyk/online-judge-template-generator/blob/master/LICENSE)\n\n[README in English](https://github.com/online-judge-tools/template-generator)\n\n\n## What is this\n\n競技プログラミングの問題を解析してテンプレートコードを出力してくれるツールです。\n[kyuridenamida/atcoder-tools](https://github.com/kyuridenamida/atcoder-tools) を参考に、その本質部分だけを抜き出して再実装しました。\n内部構造については [How it works](https://online-judge-template-generator.readthedocs.io/en/latest/how-it-works.html) に書かれています。\n\n主目的は以下のふたつです:\n\n-   不適切な入出力方法を用いたことによる TLE を回避すること。たとえば「Codeforces で `std::endl` を使って TLE する」みたいなのをなくしたい\n-   ランダムケースを生成してのテストを気軽に行えるようにすること。たとえば、サンプル AC して提出してみたら謎の WA が出たとき「これランダムケース生成して愚直解と比較すれば原因分かるだろうけど、面倒なんだよな」ってなりがちですが、この面倒を半減させ高速にデバッグできるようにしたい\n\n\n## Resources\n\nオンライン上の試用版: \u003chttps://online-judge-tools.github.io/template-generator-webapp/\u003e\n\n有志による紹介記事 (日本語):\n\n-   [Online Judge Template Generator を Windows 10 + Python で使う：AtCoder コンテストにおける提出コードの作成，テストから提出まで - はむ吉（のんびり）の練習ノート](https://hamukichi.hatenablog.jp/entry/2020/09/17/230818)\n\n\n## How to install\n\n``` console\n$ pip3 install online-judge-template-generator\n```\n\n\n## Usage\n\n`oj-template` コマンドは、指定された問題を解析し、その問題のための入出力パート (`int n; std::cin \u003e\u003e n;` など) を含むテンプレートファイル (`main.cpp` など) やランダムケース生成器 (`generate.py` など) を自動生成します。詳細は [Examples](#examples) を見てください。\n[`oj` コマンド](https://github.com/kmyk/online-judge-tools) が認識できる問題であれば何に対してでも動作します。\n\n``` console\n$ oj-template [-t TEMPLATE] URL\n```\n\n`oj-prepare` コマンドは、指定された問題やコンテストに対し、テンプレート生成やサンプルのダウンロードを一括で行います。\nこれは `oj` コマンドと `oj-template` コマンドの薄いラッパーです。\n[`oj` コマンド](https://github.com/kmyk/online-judge-tools) が認識できる問題であれば何に対してでも動作します。\n\n``` console\n$ oj-prepare URL\n```\n\n\n### Supported languages\n\n`oj-template` が認識する組み込みのテンプレートとして以下が使えます。\n\n-   `main.cpp`: C++ 解法コード\n-   `main.py`: Python 解法コード\n-   `generate.py`: Python ランダムケース生成器\n-   `generate.cpp`: C++ ランダムケース生成器\n\n\n### Generating random cases\n\nランダムケースの生成は、`oj-prepare https://...` コマンドを実行し、生成された `generate.py` を修正した後に、次のように実行してください。\n\n``` console\n$ oj generate-input \"python3 generate.py\"\n```\n\nファイル `generate.py` は `oj-template -t generate.py \"https://...\"` というコマンドの実行によっても生成できます。\n\n\n## Examples\n\n``` console\n$ oj-template https://codeforces.com/contest/1300/problem/D\n...\n\n#include \u003cbits/stdc++.h\u003e\n#define REP(i, n) for (int i = 0; (i) \u003c (int)(n); ++ (i))\n#define REP3(i, m, n) for (int i = (m); (i) \u003c (int)(n); ++ (i))\n#define REP_R(i, n) for (int i = (int)(n) - 1; (i) \u003e= 0; -- (i))\n#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) \u003e= (int)(m); -- (i))\n#define ALL(x) ::std::begin(x), ::std::end(x)\nusing namespace std;\n\nconst string YES = \"YES\";\nconst string NO = \"nO\";\nbool solve(int n, const vector\u003cint64_t\u003e \u0026 a, const vector\u003cint64_t\u003e \u0026 b) {\n    // TODO: edit here\n}\n\n// generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)\nint main() {\n    std::ios::sync_with_stdio(false);\n    std::cin.tie(nullptr);\n    constexpr char endl = '\\n';\n    int n;\n    cin \u003e\u003e n;\n    vector\u003cint64_t\u003e a(n), b(n);\n    REP (i, n) {\n        cin \u003e\u003e a[i] \u003e\u003e b[i];\n    }\n    auto ans = solve(n, a, b);\n    cout \u003c\u003c (ans ? YES : NO) \u003c\u003c endl;\n    return 0;\n}\n```\n\n``` console\n$ oj-template -t generate.py https://judge.yosupo.jp/problem/staticrmq\n...\n\n#!/usr/bin/env python3\nimport random\nimport onlinejudge_random as random_oj\n\ndef main():\n    N = random.randint(1, 10 ** 9)  # TODO: edit here\n    a = [None for _ in range(N)]\n    Q = random.randint(1, 10 ** 9)  # TODO: edit here\n    l = [None for _ in range(Q)]\n    r = [None for _ in range(Q)]\n    for i in range(N):\n        a[i] = random.randint(1, 10 ** 9)  # TODO: edit here\n    for i in range(Q):\n        l[i] = random.randint(1, 10 ** 9)  # TODO: edit here\n        r[i] = random.randint(1, 10 ** 9)  # TODO: edit here\n    print(N, Q)\n    print(*[a[i] for i in range(N)])\n    for i in range(Q):\n        print(l[i], r[i])\n\nif __name__ == \"__main__\":\n    main()\n```\n\n``` console\n$ oj-prepare https://atcoder.jp/contests/abc158\n...\n\n$ tree\n.\n├── abc158_a\n│   ├── main.cpp\n│   ├── main.py\n│   ├── generate.py\n│   └── test\n│       ├── sample-1.in\n│       ├── sample-1.in\n│       ├── sample-1.out\n│       ├── sample-2.in\n│       ├── sample-2.out\n│       ├── sample-3.in\n│       └── sample-3.out\n├── ...\n├── ...\n├── ...\n├── ...\n└── abc158_f\n    ├── main.cpp\n    ├── main.py\n    ├── generate.py\n    └── test\n        ├── sample-1.in\n        ├── sample-1.out\n        ├── sample-2.in\n        ├── sample-2.out\n        ├── sample-3.in\n        ├── sample-3.out\n        ├── sample-4.in\n        └── sample-4.out\n\n13 directories, 50 files\n```\n\n\n## Settings\n\n### oj-template\n\n`oj-template` のためのテンプレートは `-t` オプションによって指摘できます。\n組み込みで用意されているテンプレートの一覧は [onlinejudge_template_resources/template/](https://github.com/online-judge-tools/template-generator/tree/master/onlinejudge_template_resources/template) で見られます。\nたとえば [generate.cpp](https://github.com/online-judge-tools/template-generator/blob/master/onlinejudge_template_resources/template/generate.cpp) を利用したい場合は `oj-template -t generate.cpp https://...` としてください。\n\nテンプレートを自分で作成することもできます。\nテンプレート記法は [Mako](https://www.makotemplates.org/) のものを使います。\n[fastio_sample.cpp](https://github.com/kmyk/online-judge-template-generator/blob/master/onlinejudge_template_resources/template/fastio_sample.cpp) とか [customize_sample.cpp](https://github.com/kmyk/online-judge-template-generator/blob/master/onlinejudge_template_resources/template/customize_sample.cpp) とかを見ていい感じに書いてください。\nAPI ドキュメントは [onlinejudge_template.generator package](https://online-judge-template-generator.readthedocs.io/en/latest/onlinejudge_template.generator.html) にあります。\n\n自分で書いたテンプレートを `-t` オプションで指定するときは、文字列中にパス区切り文字 `/` が含まれるようにしてパスを指定してください (シェルスクリプトでの実行ファイルの指定と同様です)。\nたとえば `customized.py` というテンプレートを書いたときは、`oj-template -t ./customized.py https://...` や `oj-template -t /path/to/customized.py https://...` のように指定してください。\nまた、特定のディレクトリ (Linux の場合は `~/.config/online-judge-tools/template/`) の下に `~/.config/online-judge-tools/template/customized.py` のようにファイルを配置しておくことで、`oj-template -t customized.py https://...` のように指定できるようにもなります。組み込みのテンプレートと同じ名前のテンプレートがこのディレクトリにあれば上書きされます。\n\n### oj-prepare\n\n`oj-prepare` の設定は (Linux の場合は) `~/.config/online-judge-tools/prepare.config.toml` で行えます。MacOS の場合は `/Users/{user_name}/Library/Application Support/online-judge-tools/prepare.config.toml` で行えます。以下のように書いてください。\n\n``` toml\ncontest_directory = \"~/Desktop/{service_domain}/{contest_id}/{problem_id}\"\nproblem_directory = \".\"\n\n[templates]\n\"main.py\" = \"main.py\"\n\"naive.py\" = \"main.py\"\n\"generate.py\" = \"generate.py\"\n```\n\n設定項目:\n\n-   `problem_directory` (string): 問題の URL が指定された場合は `{problem_directory}` にファイルが用意される。\n    -   default: `.`\n    -   使える変数:\n        -   `{problem_id}`: 問題 ID (`abc123_d` など)\n-   `contest_directory` (string): コンテストの URL が指定された場合は `{contest_directory}/{problem_directory}` にファイルが用意される。(default: \n    -   default: `{problem_id}`\n    -   使える変数:\n        -   `{problem_id}`: 問題 ID (`abc123_d` など)\n        -   `{contest_id}`: コンテスト ID (`abc123` など)\n        -   `{service_domain}`: サービスのドメイン (`atcoder.jp` など)\n        -   `{service_name}`: サービスの名前 (`AtCoder` など)\n-   `templates` (table of string): value (右側) のテンプレートによる生成結果を key (左側) で指定したパスに配置する。\n    -   example: `{ \"solution.cpp\" = \"main.cpp\", \"naive.py\" = main.py\", \"generate.cpp\" = \"generate.cpp\" }`\n    -   default: `{ \"main.cpp\" = \"main.cpp\", \"main.py\" = \"main.py\", \"generate.py\" = \"generate.py\" }`\n\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonline-judge-tools%2Ftemplate-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonline-judge-tools%2Ftemplate-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonline-judge-tools%2Ftemplate-generator/lists"}