Tools to help solving problems on various online judges. This automates downloading sample cases, generating additional test cases, testing for your code, and submitting it.
- 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
Many online judges (Codeforces, AtCoder, HackerRank, etc.) are supported. For details, see the table of online-judge-tools/api-client.
The package is https://pypi.python.org/pypi/online-judge-tools .
$ pip3 install online-judge-tools
For detailed instructions, read the FAQ.
$ 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
.
$ 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
Do following steps.
- If you use a Windows environment, use Windows Subsystem for Linux (WSL). For beginners, Linux (especially, Ubuntu) is often easier than Windows.
- Also, if you use Visual Studio Code (or other IDEs), close it and forget it for a while. Don't use consoles in IDEs.
- 🐍 Install Python. If you use Ubuntu (including Ubuntu in WSL), run
$ sudo apt install python3
. - Check your Python with running
$ python3 --version
. If it saysPython 3.x.y
, it's OK.- If it says something like
Command 'python3' not found
, you have failed to install Python. - If the version of Python is too old, it's not OK. The
x
must be greater than or equal to5
. Ifx
is lower than5
, upgrade your Python.
- If it says something like
- 📦 Install pip. If you use Ubuntu (including Ubuntu in WSL), run
$ sudo apt install python3-pip
. - Check your pip with running
$ pip3 --version
. If it says something likepip x.y.z ...
, it's OK.- If it says something like
Command 'pip3' not found
, you have failed to install pip. - Even if
pip3
is not found, you may be able to usepython3 -m pip
instead ofpip3
. Try$ python3 -m pip --version
. If it sayspip x.y.z ...
, it's OK. - Don't use
pip
orpip2
. Usepip3
.
- If it says something like
- 🎯 Run
$ pip3 install online-judge-tools
to install online-judge-tools. If it saysSuccessfully installed online-judge-tools-x.y.z
(or,Requirement already satisfied: online-judge-tools
), it's OK.- If it says
Permission denied
, run$ sudo pip3 install online-judge-tools
or$ pip3 install --user online-judge-tools
.
- If it says
- Check online-judge-tools with
$ oj --version
. If It must say something likeonline-judge-tools x.y.z
.- If it says something like
Command 'oj' not found
, you need to setPATH
.- Find the path of the
oj
file with running$ find / -name oj 2> /dev/null
. The file is often at/home/ubuntu/.local/bin/oj
or/usr/local/bin/oj
. - Check the found
oj
file is actuallyoj
, with running$ /home/ubuntu/.local/bin/oj --version
. - Add the directory which contains the
oj
to yourPATH
. For example, ifoj
is/home/ubuntu/.local/bin/oj
, writeexport PATH="/home/ubuntu/.local/bin:$PATH"
in the end of~/.bashrc
.- Don't write
export PATH="$PATH:/home/ubuntu/.local/bin/oj"
. It's not a directory. - If you don't use bash, write a right settings to the right file depending on your shell. For example, if you use Mac OS, your shell might zsh. For zsh, write the same command to
~/.zshrc
.
- Don't write
- Reload the configuration with
source ~/.bashrc
.- If you don't use bash, use an appropriate way.
- Check your
PATH
with$ echo $PATH
. If it says/home/ubuntu/.local/bin:...
, it's OK.
- Find the path of the
- If it says something like
ModuleNotFoundError: No module named 'onlinejudge'
, you have failed to install online-judge-tools and your environment is broken. Run$ pip3 install --force-reinstall online-judge-tools
to reinstall. - If it says something like
SyntaxError: invalid syntax
, you have usedpip2
by mistake. Run$ pip2 uninstall online-judge-tools
, and retry to install.
- If it says something like
- That's all.
If you couldn't read many sentences of above instructions (e.g. if you didn't know what "run $ python3 --version
" means), please ask your friends for help.
If you cannot install online-judge-tools even following the instructions, please add comments to this issue.
- 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.
- Yes, you can use the
- Can I download all sample cases of all problems at once?
- No, but you can use
oj-prepare
command in kmyk/online-judge-template-generator.
- No, but you can use
- Can I automatically compile my source code before testing?
- Yes, use your shell. Run
$ g++ main.cpp && oj t
.
- Yes, use your shell. Run
- 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.
- Yes, use your shell. Run
- Can I remove the delays and the
[y/N]
confirmation before submitting code?- Yes, put
--wait=0
option and--yes
option tooj 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.
- Yes, put
- 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
.
- Yes, remove the history file, whose name is
- Is my password stored?
- Your password is not stored into any files. This program stores only your session tokens (but of course, it's still credentials). Please read onlinejudge/_implementation/command/login.py.
- 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, writealias oj-test-python='oj t -c "python3 main.py"'
(alias) to.bashrc
and use$ oj-test-python
, or writefunction oj-test-python() { FILE="$1" ; shift ; oj t -c "python3 '$FILE'" "$@" ; }
(function) and useoj-test-python main.py
.
- No. You can use your
For other questions, use Gitter or other SNSs.
conflicted:
not conflicted:
- shivawu/topcoder-greed for Topcoder Single Round Match
- FakePsyho/mmstats for Topcoder Marathon Match
- https://community.topcoder.com/tc?module=Static&d1=applet&d2=plugins
projects depending on kmyk/online-judge-tools:
- 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
- libraries using this for CI:
- kmyk/competitive-programming-library is my library for competitive programming, which uses
oj
via kmyk/online-judge-verify-helper - beet-aizu/library also uses kmyk/online-judge-verify-helper
- blue-jam/ProconLibrary uses
oj
for CI from their own scripts
- kmyk/competitive-programming-library is my library for competitive programming, which uses
- others:
- kmyk/online-judge-verify-helper automates testing your library for competitive programming and generate documents
- kmyk/online-judge-template-generator analyzes problems and generates templates including auto-generated input/output parts
- fukatani/rujaion is an IDE for competitive-programming with Rust
See CONTRIBUTING.md
For the full list of contributors, see CHANGELOG.md or the contributors page of GitHub.
- @kmyk (AtCoder: kimiyuki, Codeforces: kimiyuki) (owner)
- @fukatani (AtCoder: ryoryoryo111) (collaborator)
- @kawacchu (AtCoder: kawacchu)
MIT License