It is a procedure to acquire, test, and submit a test case on the terminal (Mac) using ʻatcoder-cli, ʻonline-judge-tools
.
When I started AtCoder, I used the code test on the contest page without any special environment maintenance, but by improving the environment as described in this article, everything will be completed on Visual Studio Code + iTerm2. The speed of submission has increased.
Installation of necessary tools
$ pip3 install online-judge-tools
$ npm install -g atcoder-cli
$ pip3 install selenium
Log in to AtCoder with the tool
$ acc login
$ oj login https://atcoder.jp/
Make sure that all problem directories are created. For example, for AtCoder Begginer Contest, let the acc new abcXXX command create problems a ~ f
$ acc config default-task-choice all
Show the location of the config directory
$ acc config-dir
Set the template. Create a folder with the template name in the config directory, and create the template source code (example: main.py
) and the template configuration file (template.json
) in it.
#Go to config directory
$ cd /Users/xxxxxxxxxx/Library/Preferences/atcoder-cli-nodejs
$ mkdir py
$ cd py
$ touch main.py template.json
When the problem directory is created, main.py is created, and to submit it to main.py, write as follows.
$ cat template.json
{
"task":{
"program": ["main.py"],
"submit": "main.py"
}
}
Edit the default settings when main.py was created. #! / usr / bin / env python3
is required. In my case, I write additional common input patterns by default.
$ cat main.py
#!/usr/bin/env python3
S = input()
N = int(input())
S = input().split()
A, B, C = input().split()
L = list(map(int, input().split()))
H, N = map(int, input().split())
Set the default template to py (files set in the py directory apply)
$ acc config default-template py
Check template
$ acc templates
search template directories in /Users/xxxxxxxxxx/Library/Preferences/atcoder-cli-nodejs
NAME SUBMIT-PROGRAM
py main.py
The example below is for creating a directory for AtCoder Bergginer Contest 154. A file of main.py
and test input and output is created.
$ acc new abc154
$ tree
.
├── a
│ ├── main.py
│ └── tests
│ ├── sample-1.in
│ ├── sample-1.out
│ ├── sample-2.in
│ └── sample-2.out
├── b
│ ├── main.py
│ └── tests
│ ├── sample-1.in
│ ├── sample-1.out
│ ├── sample-2.in
│ ├── sample-2.out
│ ├── sample-3.in
│ └── sample-3.out
├── c
│ ├── main.py
│ └── tests
│ ├── sample-1.in
│ ├── sample-1.out
│ ├── sample-2.in
│ ├── sample-2.out
│ ├── sample-3.in
│ └── sample-3.out
├── contest.acc.json
├── d
│ ├── main.py
│ └── tests
│ ├── sample-1.in
│ ├── sample-1.out
│ ├── sample-2.in
│ ├── sample-2.out
│ ├── sample-3.in
│ └── sample-3.out
├── e
│ ├── main.py
│ └── tests
│ ├── sample-1.in
│ ├── sample-1.out
│ ├── sample-2.in
│ ├── sample-2.out
│ ├── sample-3.in
│ ├── sample-3.out
│ ├── sample-4.in
│ └── sample-4.out
└── f
├── main.py
└── tests
├── sample-1.in
├── sample-1.out
├── sample-2.in
└── sample-2.out
12 directories, 41 files
Once the program is complete, test it using ʻonline-judge-tools` (atcoder-cli has no test commands)
$ oj t -c "python3 main.py" -d ./tests/
In my case, I put alias so that I can test with only the test
command in the directory of the target problem.
$ vim ~/.bash_profile
#Add the following
alias test='oj t -c "python3 main.py" -d ./tests/'
$ source ~/.bash_profile
Run the test
command in the directory of interest
$ pwd
/xxxxx/atcoder/problem/abc151/a
$ test
If you want to test in a test case other than the problem statement, such as during debugging, execute the program normally and enter the test case. In the case of the following programs
n = int(input())
print(n)
Check if the expected result is returned by getting the output by executing and inputting as follows.
$ python main.py
1 #input
1 #output
By executing the following command in the directory in question, it will automatically jump to the AtCoder page and submit it.
$ acc s
Recommended Posts