Package: online-judge-template-generator
online-judge-tools/template-generatorREADME 日本語バージョンWhat is thisThis tool analyzes problems and generates template codes for competitive programming.Online Demo:https://online-judge-tools.github.io/template-generator-webapp/How to install$pip3installonline-judge-template-generatorUsageoj-templatecommand analyzes the specified problem and generates the template files (e.g.main.cpp) including input/output part (e.g.int n; std::cin >> n;) and the generators (e.g.generate.py) of random test cases for the problem. SeeExamples.
This works on many online judges whichojcommandworks.$oj-template[-tTEMPLATE]URLoj-preparecommand prepares some template files and test cases for a problem or a contest at once. This is a thin wrapper ofojcommand andoj-templatecommand.
This works on many online judges whichojcommandworks.$oj-prepareURLSupported languagesThe following template files are prepared as builtin ofoj-templatecommand.main.cpp: solution in C++main.py: solution in Pythongenerate.py: random case generator in Pythongenerate.cpp: random case generator in C++The builtin templates invokeclang-formatcommandandyapfcommandwhen they exist.
Please install them too if you want to generate better formatted code.Generating random casesTo generate random cases, please runoj-prepare https://...command, edit the generatedgenerate.pyfile, and run the following command:$ojgenerate-input"python3 generate.py"You can also generate the filegenerate.pywith the running the commandoj-template -t generate.py "https://...".Examples$oj-templatehttps://codeforces.com/contest/1300/problem/D...#include<bits/stdc++.h>#defineREP(i,n)for(inti=0;(i)<(int)(n);++(i))#defineREP3(i,m,n)for(inti=(m);(i)<(int)(n);++(i))#defineREP_R(i,n)for(inti=(int)(n)-1;(i)>=0;--(i))#defineREP3R(i,m,n)for(inti=(int)(n)-1;(i)>=(int)(m);--(i))#defineALL(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-tgenerate.pyhttps://judge.yosupo.jp/problem/staticrmq...#!/usr/bin/envpython3import randomimport onlinejudge_random as random_ojdef main():N = random.randint(1, 10 ** 9)  # TODO: edit herea = [None for _ in range(N)]Q = random.randint(1, 10 ** 9)  # TODO: edit herel = [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 herefor i in range(Q):l[i] = random.randint(1, 10 ** 9)  # TODO: edit herer[i] = random.randint(1, 10 ** 9)  # TODO: edit hereprint(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-preparehttps://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.out13 directories, 50 filesSettingsoj-templateThe template file foroj-templatecommand can be specified with the-toption.
You can see the list of builtin template files atonlinejudge_template_resources/template/.
For example, if you want to usegenerate.cpp, please run asoj-template -t generate.cpp https://....You can make a new template by yourself.
The format of template files isMako's one.
Please write by reference to existing files likefastio_sample.cpporcustomize_sample.cpp>
API documentation exists atonlinejudge_template.generator package.To specify your new template file with-toption, please include the path separator character/in the given path (this is similar to the behavior of executing a command out of PATH in shell).
For example, if you write a template file namedcustomized.py, please runoj-template -t ./customized.py https://...oroj-template -t /path/to/customized.py https://....
Also you can use certain directory (when you use Linux, it's~/.config/online-judge-tools/template/) to place template files like~/.config/online-judge-tools/template/customized.py. If templates exist in this directory, you can specify them asoj-template -t customized.py https://.... If templates files whose names are the same to builtin templates, they are override the builtin files.oj-prepareThere is the config file foroj-prepareat~/.config/online-judge-tools/prepare.config.toml(in Linux).
Please write as the following.contest_directory="~/Desktop/{service_domain}/{contest_id}/{problem_id}"problem_directory="."[templates]"main.py"="main.py""naive.py"="main.py""generate.py"="generate.py"Available items:problem_directory(string): When a URL of a problem is given to the command, use{problem_directory}for the directory.default:.available vairables:{problem_id}: problem ID (e.g.abc123_d)contest_directory(string): When a URL of a contest is given to the command, use{contest_directory}/{problem_directory}for the directory.default:{problem_id}available vairables:{problem_id}: problem ID (e.g.abc123_d){contest_id}: contest ID (e.g.abc123){service_domain}: the domain of the online judge (e.g.codeforces.com){service_name}: the name of the online judge (e.g.Codeforces)templates(table of string): places the generated code specified by value (the right of=) into paths specified by key (the left of=).example:{ "solution.cpp" = "main.cpp", "naive.py" = main.py", "generate.cpp" = "generate.cpp" }default:{ "main.cpp" = "main.cpp", "main.py" = "main.py", "generate.py" = "generate.py" }LicenseMIT License