iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🏅

Getting Started with AtCoder and online-judge-tools/oj

に公開

I'm starting with AtCoder.
After trying the method of entering code into the text field of a browser, I wanted to go a cooler way, so I tried submitting using online-judge-tools/oj.

The problem I tried was the first practice problem, PracticeA (https://atcoder.jp/contests/abs/tasks/practice_1), from the AtCoder Beginners Selection.

Installing oj

I installed it by following the steps described on the official website.

Creating a test environment

Following the advice in Let's introduce online-judge-tools!, I created a directory for AtCoder named atcoder and a directory for this specific problem named practiceA under it.

$ mkdir atcoder
$ cd atcoder
$ mkdir practiceA

Then, under the practiceA directory, I executed $ oj d {URL of the problem page}.

$ cd practiceA
$ oj d https://atcoder.jp/contests/abs/tasks/practice_1

As a result, a test directory containing test data was downloaded under the practiceA directory.

Creating the program

Under the atcoder directory, I created a Python program practiceA.py (which is the answer itself) with the following content.

a = int(input())
b, c = map(int, input().split())
s = input()
print("{} {}".format(a+b+c, s))

At this point, the structure under the atcoder/practiceA directory is as follows.

$ ls -1R  
practiceA.py
test

./test:
sample-1.in
sample-1.out
sample-2.in
sample-2.out

Testing

Run the following command in the atcoder/practiceA directory to test.

$ oj t -c "python3 practiceA.py" -d test

Then, the following results will be displayed after the command.

[INFO] online-judge-tools 11.1.1 (+ online-judge-api-client 10.7.1)
[INFO] 2 cases found
time: illegal option -- f
usage: time [-lp] <command>
[WARNING] GNU time is not available: time

[INFO] sample-1
[INFO] time: 0.054032 sec
[SUCCESS] AC

[INFO] sample-2
[INFO] time: 0.063664 sec
[SUCCESS] AC

[INFO] slowest: 0.063664 sec  (for sample-2)
[SUCCESS] test success: 2 cases

AC means that the test has passed.

Submitting

You only need to run the following in the atcoder/practiceA directory.

$ oj s practiceA.py

By doing this, practiceA.py is uploaded to AtCoder, and the judgment results will be displayed in your browser.

Even Cooler

Discussion