Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

4 online-judge-tools features you might have missed
Difference between en3 and en4, changed 1,571 character(s)
Do you use [online-judge-tools](https://github.com/kmyk/online-judge-tools)?↵
If not, I
 believe it is valuable tool to try.↵

Your operation in competitive programming will become automated and the competition programming experience will be comfortable.↵

Good tutorial is [here](https://online-judge-tools.readthedocs.io/en/master/introduction.en.html).↵

BTW, `online-judge-tool` seems simple.↵

But if you execute `oj test --help`, you can find about 20 command line options for `oj test`.↵

Other subcommand (`login`, `download` and etc.) also have many command line options.↵

Actually, these are many features.↵

Therefore, today I want to 
introduce my favorite online-judge-tools features.↵

## 1. Side-by-Side diff↵

This is very new feature for `oj test`.↵

Sometimes, finding differences between your answer and expectation is cumbersome task.↵

For example,↵

``` ↵
$ oj test -c './a.out'↵
[*] 1 cases found↵

[*] sample-1↵
[x] time: 0.054696 sec↵
[-] WA↵
output:↵
7↵
1 5 1 3↵
7 7 89 9 2 2 6 5↵
2 4 6 1 8 5↵
9 10 0 29 56↵

expected:↵
7↵
1 5 1 3↵
7 7 89 9 2 2 6 5↵
2 4 6 1 3 5↵
9 10 0 29 56↵
```↵

Can you find where difference is
 between output and expected?↵

If you uses side-by-side display option(`-S`),↵

![ ](/predownloaded/64/64/64643f48b7d9ba681e712913638f86ff469c83478e/9f/8e9fe9ef75cea54ae43dee9da348533f957cedd0.png)

Great! You can find "3" i
n expect was replaced byto "8" in output in a moment!.


## 2. MLE and TLE checking↵

Since almost all of problems are limits computation time and memory consumption
.,
Iit's natural that you want to confirm not only that the output matches the expected value, but also these limitations.↵

You only have to add `--tle` or `--mle` options for checking these limitations.↵

ex.↵
```↵
$ oj t -c './a.out' --tle 2.5  # 2.5sec↵
[*] 1 cases found↵

[*] sample-1↵
[x] time: 2.503372 sec↵
[-] TLE↵
```↵

```↵
$ oj t -c './a.out' --mle 56  # 56MB↵
```↵

Note:↵
Currently, this feature requires `gnu time`.↵
Therefore, unfortunately, Windows users can't access this feature.↵

## 3. Floating point error judge↵

Some problem requires floating point output. (ex. 2.500000)↵
In many situation, relational and absolute error is allowed for these problems.↵

`oj test` can handle these errors by `-e` option.↵

If problem expectation `3` and your program outputs `3.00000001`↵

```↵
$ oj t -c 'echo 3.00000001'↵
[*] 1 cases found↵

[*] sample-1↵
[x] time: 0.004793 sec↵
[-] WA↵
output:↵
3.00000001↵

expected:↵
3↵
```↵

In this situation, `oj` recognize your output as "Wrong Answer".↵
But if you indicated allowed error by `-e` option, 
result will become changed.

```↵
$ oj t -c 'echo 3.00000001' -e 0.000001↵
[*] 1 cases found↵

[*] sample-1↵
[x] time: 0.004088 sec↵
[+] AC↵
```↵

Good, `oj` result becomes "All Correct".↵
Here, `oj t -c 'echo 3.00000001' -e 1e-5` is equivalent with `oj t -c 'echo 3.00000001' -e 0.000001`.↵


## 4. API↵

This is feature for tool developers.↵



You can access `online-judge-tools` inner functions via Python and you can construct powerful your own contest helper.↵

For example, I implemented "go to next problem" function for my [IDE](https://github.com/fukatani/rujaion).↵

Snippet to get next problem URL is here.↵

```python↵
from onlinejudge import dispatch↵
from onlinejudge._implementation.utils import (↵
    default_cookie_path,↵
    with_cookiejar,↵
    new_session_with_our_user_agent,↵
)↵

def get_next_problem(cur_problem_url: str) -> str:↵
    cur_problem = dispatch.problem_from_url(cur_problem_url)↵
    contest = cur_problem.get_contest()↵
    with with_cookiejar(new_session_with_our_user_agent(), path=default_cookie_path) as sess:↵
        problems = contest.list_problems(session=sess)↵
        for i, problem in enumerate(problems):↵
            if problem == cur_problem:↵
                next = problems[(i + 1) % len(problems)].get_url()↵
                return next↵

next_url = get_next_problem("https://codeforces.com/contest/1312/problem/B")↵
print(next_url)↵
```↵

If you logged in Codeforce via `online-judge-tools`, you will get "https://codeforces.com/contest/1312/problem/C".↵
I hope there are more great features will be developed by you!↵

Thanks,

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English terraformer 2020-03-18 17:03:35 81
en5 English terraformer 2020-03-17 16:57:11 2 Tiny change: '.\n\nex.\n```\n$ o' -> '.\n\nex.\n\n```\n$ o'
en4 English terraformer 2020-03-17 16:55:52 1571 (published)
en3 English terraformer 2020-03-17 16:33:39 1490
en2 English terraformer 2020-03-16 18:08:15 555
en1 English terraformer 2020-03-16 18:01:54 1222 Initial revision (saved to drafts)