Skip to main content

CLI tool to solve problems of competitive programming

Project description

online-judge-tools/oj

test PyPI Downloads PyPI Join the chat at https://gitter.im/online-judge-tools/community

oj is a command to help solving problems on various online judges. This command automates downloading sample cases, generating additional test cases, testing for your code, and submitting it.

Screencast

screencast

Features

  • Download sample cases
  • Download system test cases
  • Login
  • Submit your code
  • Test your code
  • Test your code for reactive problems
  • Generate input files from generators
  • Generate output files from input and reference implementation

For the detailed documentation, read docs/getting-started.md. For Japanese: 日本語バージョンのドキュメントは docs/getting-started.ja.md にあります。

Many online judges (Codeforces, AtCoder, HackerRank, etc.) are supported. For the full list, see the table of online-judge-tools/api-client.

How to install

The package is https://pypi.python.org/pypi/online-judge-tools PyPI.

$ pip3 install online-judge-tools

For detailed instructions, read docs/INSTALL.md. For Japanese: 日本語バージョンのドキュメントは docs/INSTALL.ja.md にあります。

How to use

$ oj download [--system] URL
$ oj login URL
$ oj submit [URL] FILE
$ oj test [-c COMMAND] [TEST...]
$ oj test-reactive [-c COMMAND] JUDGE_COMMAND
$ oj generate-input GENERATOR_COMMAND
$ oj generate-output [-c COMMAND] [TEST...]

For details, see $ oj --help.

Example

$ oj download http://agc001.contest.atcoder.jp/tasks/agc001_a
[+] problem recognized: <onlinejudge.atcoder.AtCoder object at 0x7f2925a5df60>
[x] GET: http://agc001.contest.atcoder.jp/tasks/agc001_a
[+] 200 OK

[*] sample 0
[x] input: 入力例 1
2
1 3 1 2
[+] saved to: test/sample-1.in
[x] output: 出力例 1
3
[+] saved to: test/sample-1.out

[*] sample 1
[x] input: 入力例 2
5
100 1 2 3 14 15 58 58 58 29
[+] saved to: test/sample-2.in
[x] output: 出力例 2
135
[+] saved to: test/sample-2.out

[*] sample 2
[x] input: Sample Input 1
2
1 3 1 2
[+] saved to: test/sample-3.in
[x] output: Sample Output 1
3
[+] saved to: test/sample-3.out

[*] sample 3
[x] input: Sample Input 2
5
100 1 2 3 14 15 58 58 58 29
[+] saved to: test/sample-4.in
[x] output: Sample Output 2
135
[+] saved to: test/sample-4.out

FAQ

  • I usually make one directory per one contest (or, site). Can I keep using this style?
    • Yes, you can use the --directory (-d) option or $ rm -rf test/. However, we don't recommend this style, because you should make additional test cases by yourself and run stress tests to maximize your rating.
  • Can I download all sample cases of all problems at once?
  • Can I automatically compile my source code before testing?
    • Yes, use your shell. Run $ g++ main.cpp && oj t.
  • Can I automatically submit code after it passes tests?
    • Yes, use your shell. Run $ oj t && oj s main.cpp. By the way, you need to take care of problems whose sample cases are not so strong.
  • Can I remove the delays and the [y/N] confirmation before submitting code?
    • Yes, put --wait=0 option and --yes option to oj s subcommand. Of course, we don't recommend this. They exist for failsafe. For example, please consider a situation where if you save 3 seconds, you will move up 3 places on the standings. In such a case, if you get a penalty of 5 minutes, then you will move down at least 300 places on the standings.
  • Can I clear my download history to omit the URL of the problem to submit?
    • Yes, remove the history file, whose name is download-history.jsonl.
  • Is my password stored?
  • Can I specify problems by their IDs or names, instead of URLs?
    • No. It may sound nice, but actually, hard to use and maintain.
  • Does the config file exist?
    • No. You can use your .bashrc (or similar files) instead. It's a config file of your shell. Read man bash and write shell aliases or shell functions. For example, if you want to use Python code for tests by default, write alias oj-test-python='oj t -c "python3 main.py"' (alias) to .bashrc and use $ oj-test-python, or write function oj-test-python() { FILE="$1" ; shift ; oj t -c "python3 '$FILE'" "$@" ; } (function) and use oj-test-python main.py.

For other questions, use Gitter Join the chat at https://gitter.im/online-judge-tools/community or other SNSs.

Resources

Articles

in Japanese:

Related Tools

conflicted:

not conflicted:

projects depending on kmyk/online-judge-tools:

  1. wrappers:
    • Tatamo/atcoder-cli is a thin wrapper optimized for AtCoder
    • kjnh10/pcm is a tool which internally uses online-judge-tools
    • some people use oj via Visual Studio Code
  2. libraries using this for CI:
  3. others:

Maintainers

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

online_judge_tools-11.2.0-py3-none-any.whl (45.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page