A simple template generator for competitive programming
Project description
Online Judge Template Generator
What is this
競技プログラミングテンプレートを作ってくれるやつです。 kyuridenamida/atcoder-tools を参考に、その本質部分だけを抜き出して再実装しました。 内部構造については How it works に書かれています。
主目的は以下のふたつです:
- 不適切な入出力方法を用いたことによる TLE を回避すること。たとえば「Codeforces で
std::endl
を使って TLE する」みたいなのをなくしたい - ランダムケースを生成してのテストを気軽に行えるようにすること。たとえば、サンプル AC して提出してみたら謎の WA が出たとき「これランダムケース生成して愚直解と比較すれば原因分かるだろうけど、面倒なんだよな」ってなりがちですが、この面倒を半減させ高速にデバッグできるようにしたい
How to install
$ pip3 install online-judge-template-generator
Usage
oj-template
コマンドは、指定された問題に対し、入出力パートを自動生成します。
入出力解析は (精度は別として) たいていのオンラインジャッジで動きます。
$ oj-template [-t TEMPLATE] URL
oj-prepare
コマンドは、指定された問題やコンテストに対し、テンプレート生成やサンプルのダウンロードを一括で行います。
oj
コマンド が動くやつなら何に対してでも動きます。
$ oj-prepare URL
Supported languages
oj-template
が認識する組み込みのテンプレートとして以下が使えます。
main.cpp
: C++ 解法コードmain.py
: Python 解法コードgenerate.py
: Python ランダムケース生成器generate.cpp
: C++ ランダムケース生成器
(他にもいくつかありますが、それらは突然削除されることがあります。)
Generating random cases
ランダムケースの生成は、oj-prepare
コマンドがデフォルトで生成する generate.py
を修正した後に、次のように実行してください。
$ oj generate-input "python3 generate.py"
ファイル generate.py
は oj-template -t generate.py "https://..."
というコマンドの実行によっても生成できます。
また、ランダムケース生成を補助するための module onlinejudge_random
が用意されています。詳細はドキュメントを確認してください。
Examples
$ oj-template https://codeforces.com/contest/1300/problem/D
...
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
const string YES = "YES";
const string NO = "nO";
bool solve(int n, const vector<int64_t> & a, const vector<int64_t> & b) {
// TODO: edit here
}
// generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
int n;
cin >> n;
vector<int64_t> a(n), b(n);
REP (i, n) {
cin >> a[i] >> b[i];
}
auto ans = solve(n, a, b);
cout << (ans ? YES : NO) << endl;
return 0;
}
$ oj-template -t generate.py https://judge.yosupo.jp/problem/staticrmq
...
#!/usr/bin/env python3
import random
import onlinejudge_random as random_oj
def main():
N = random.randint(1, 10 ** 9) # TODO: edit here
a = [None for _ in range(N)]
Q = random.randint(1, 10 ** 9) # TODO: edit here
l = [None for _ in range(Q)]
r = [None for _ in range(Q)]
for i in range(N):
a[i] = random.randint(1, 10 ** 9) # TODO: edit here
for i in range(Q):
l[i] = random.randint(1, 10 ** 9) # TODO: edit here
r[i] = random.randint(1, 10 ** 9) # TODO: edit here
print(N, Q)
print(*[a[i] for i in range(N)])
for i in range(Q):
print(l[i], r[i])
if __name__ == "__main__":
main()
$ oj-prepare https://atcoder.jp/contests/abc158
...
$ tree
.
├── abc158_a
│ ├── main.cpp
│ ├── main.py
│ ├── generate.py
│ └── test
│ ├── sample-1.in
│ ├── sample-1.in
│ ├── sample-1.out
│ ├── sample-2.in
│ ├── sample-2.out
│ ├── sample-3.in
│ └── sample-3.out
├── ...
├── ...
├── ...
├── ...
└── abc158_f
├── main.cpp
├── main.py
├── generate.py
└── test
├── sample-1.in
├── sample-1.out
├── sample-2.in
├── sample-2.out
├── sample-3.in
├── sample-3.out
├── sample-4.in
└── sample-4.out
13 directories, 50 files
Settings
oj-template
oj-template
のためのテンプレートは -t
オプションによって指摘できます。
組み込みで用意されているテンプレートの一覧は onlinejudge_template_resources/template/ で見られます。
たとえば generate.cpp を利用したい場合は oj-template -t generate.cpp https://...
としてください。
テンプレートを自分で作成することもできます。 テンプレート記法は Mako のものを使います。 fastio.cpp とか customize_sample.cpp とかを見ていい感じに書いてください。 API ドキュメントは onlinejudge_template.generator package にあります。
自分で書いたテンプレートを指定するときは、文字列中にパス区切り文字 /
が含まれるようにしてパスを指定してください (シェルスクリプトでの実行ファイルの指定と同様です)。
たとえば customized.py
というテンプレートを書いたときは、oj-template -t ./customized.py https://...
や oj-template -t /path/to/customized.py https://...
のように指定してください。
また、ディレクトリ ~/.config/online-judge-tools/template/
の下に ~/.config/online-judge-tools/template/customized.py
のようにファイルを配置しておくことで、oj-template -t customized.py https://...
のように指定できるようにもなります。~/.config/online-judge-tools/template/
を使えば組み込みのテンプレートを上書きすることができます。
oj-prepare
oj-prepare
の設定は ~/.config/online-judge-tools/prepare.config.toml
で行えます。
以下のように書いてください。
contest_directory = "~/Desktop/{service_domain}/{contest_id}/{problem_id}"
problem_directory = "."
[templates]
"main.py" = "main.py"
"naive.py" = "main.py"
"generate.py" = "generate.py"
設定項目:
problem_directory
(string): 問題の URL が指定された場合は{problem_directory}
にファイルが用意される。- default:
.
- 使える変数:
{problem_id}
: 問題 ID (abc123_d
など)
- default:
contest_directory
(string): コンテストの URL が指定された場合は{contest_directory}/{problem_directory}
にファイルが用意される。(default:- default:
{problem_id}
- 使える変数:
{problem_id}
: 問題 ID (abc123_d
など){contest_id}
: コンテスト ID (abc123
など){service_domain}
: サービスのドメイン (atcoder.jp
など){service_name}
: サービスの名前 (AtCoder
など)
- default:
templates
(table of string): value (右側) のテンプレートによる生成結果を key (左側) で指定したパスに配置する。- default:
{ "main.cpp" = "main.cpp", "main.py" = "main.py", "generate.py" = "generate.py" }
- default:
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for online_judge_template_generator-4.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b47454d944089dea8504319e06dc26659a383c743f2ef54fca0060fca0dd734 |
|
MD5 | dcf5b66e82f4cf889c4b7dffe92faf58 |
|
BLAKE2b-256 | dae26c1a59fd1a60f91c778b5420c08226ddb8a064414a0669018850fb5cc4b2 |