Code Monkey home page Code Monkey logo

oj's Introduction

online-judge-tools/oj

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

日本語版の README.md

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.

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.

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
[INFO] online-judge-tools 11.2.0 (+ online-judge-api-client 10.8.0)
[INFO] load cookie from: /home/user/.local/share/online-judge-tools/cookie.jar
[NETWORK] GET: https://atcoder.jp/contests/agc001/tasks/agc001_a
[NETWORK] 200 OK

[INFO] sample 0
[INFO] input: sample-1
2
1 3 1 2

[SUCCESS] saved to: test/sample-1.in
[INFO] output: sample-1
3

[SUCCESS] saved to: test/sample-1.out

[INFO] sample 1
[INFO] input: sample-2
5
100 1 2 3 14 15 58 58 58 29

[SUCCESS] saved to: test/sample-2.in
[INFO] output: sample-2
135

[SUCCESS] saved to: test/sample-2.out

$ cat <<EOF > main.py
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
ans = max(a)
print(ans)
EOF

$ oj t -c "python3 main.py"
[INFO] online-judge-tools 11.2.0 (+ online-judge-api-client 10.8.0)
[INFO] 2 cases found

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

[INFO] sample-2
[INFO] time: 0.043763 sec
[FAILURE] WA
input:
5
100 1 2 3 14 15 58 58 58 29

output:
3

expected:
135


[INFO] slowest: 0.043763 sec  (for sample-2)
[INFO] max memory: 10.064000 MB  (for sample-2)
[FAILURE] test failed: 1 AC / 2 cases

FAQ

  • Can I use Python (or Rust, D, Java, F#, Haskell, etc.) instead of C++?
    • Yes. Please use --command (-c) option if needed. For example, for Python, you can run $ oj t -c "python3 main.py".
  • 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. These options 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.
  • Are my passwords stored?
  • 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"' to .bashrc and use $ oj-test-python.

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

Resources

Related Tools

conflicted:

not conflicted:

projects collaborating with kmyk/online-judge-tools:

Maintainers

License

MIT License

oj's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oj's Issues

提出状況を引っぱってきたい

ACの監視や難易度推定とかやりたい
あとコードを解析して問題のカテゴリやタグの自動推定もやりたい。変数名見るだけでけっこういけそう。しかもまだ誰もやってなさそうだし

test for reactive problems

reactive問のテストを手元でするの、pwntoolsでなんとかなるけど、もっといい感じにしたい

yukicoder No.104 国道 で正常に動きません

% oj download http://yukicoder.me/problems/no/104                                [~/Documents/yukicoder/100/104]+[master]
[x] problem recognized: <onlinejudge.yukicoder.YukicoderProblem object at 0x1072ac588>: http://yukicoder.me/problems/no/104
[*] load cookie from: /Users/yuichi/local/share/onlinejudge/cookie.jar
[x] GET: https://yukicoder.me/problems/no/104
[x] 200 OK
Traceback (most recent call last):
  File "/Users/yuichi/Programs/online-judge-tools/main.py", line 151, in <module>
    main()
  File "/Users/yuichi/Programs/online-judge-tools/main.py", line 140, in main
    download(args)
  File "/Users/yuichi/Programs/online-judge-tools/main.py", line 34, in download
    samples = problem.download(session=sess, **kwargs)
  File "/Users/yuichi/Programs/online-judge-tools/onlinejudge/yukicoder.py", line 91, in download
    return self.download_samples(session=session)
  File "/Users/yuichi/Programs/online-judge-tools/onlinejudge/yukicoder.py", line 105, in download_samples
    it = self._parse_sample_tag(pre)
  File "/Users/yuichi/Programs/online-judge-tools/onlinejudge/yukicoder.py", line 138, in _parse_sample_tag
    return utils.textfile(tag.string.lstrip()), pprv.string + ' ' + prv.string
AttributeError: 'NoneType' object has no attribute 'lstrip'

動かない

% oj download http://yukicoder.me/problems/no/475                                [~/Documents/yukicoder/400/475]+[master]
[+] problem recognized: <onlinejudge.yukicoder.Yukicoder object at 0x102c01240>
[x] GET: https://yukicoder.me/problems/no/475
[x] 200 OK
Traceback (most recent call last):
  File "/Users/yuichi/Downloads/online-judge-tools/main.py", line 165, in <module>
    main()
  File "/Users/yuichi/Downloads/online-judge-tools/main.py", line 154, in main
    download(args)
  File "/Users/yuichi/Downloads/online-judge-tools/main.py", line 52, in download
    samples = problem.download(session=sess, **kwargs)
  File "/Users/yuichi/Downloads/online-judge-tools/onlinejudge/yukicoder.py", line 28, in download
    return self.download_samples(session=session)
  File "/Users/yuichi/Downloads/online-judge-tools/onlinejudge/yukicoder.py", line 31, in download_samples
    soup = bs4.BeautifulSoup(content, 'lxml')
  File "/usr/local/lib/python3.5/site-packages/bs4/__init__.py", line 165, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

CS Academy 対応

出ることにしたので
HackerRank同様に綺麗に取れるはず

example downloader: 失敗: AOJ 2511. 沈みゆく島

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2511&lang=jp

$ oj dl 'http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2511&lang=jp'
[x] problem recognized: <onlinejudge.aoj.AOJProblem object at 0x7ff62f999710>: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2511&lang=jp
[*] load cookie from: /home/user/.local/share/onlinejudge/cookie.jar
[x] GET: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2511
[x] 200 OK
[*] save cookie to: /home/user/.local/share/onlinejudge/cookie.jar

scanner generator: 解析失敗 KUPC 2017 I

http://kupc2017.contest.atcoder.jp/tasks/kupc2017_i

x(2) でなくて x(k)

$ oj g/s http://kupc2017.contest.atcoder.jp/tasks/kupc2017_i
[!] This feature is experimental.
[x] problem recognized: <onlinejudge.atcoder.AtCoderProblem object at 0x7f259d908908>: http://kupc2017.contest.atcoder.jp/tasks/kupc2017_i
[*] load cookie from: /home/user/.local/share/onlinejudge/cookie.jar
[x] GET: http://kupc2017.contest.atcoder.jp/tasks/kupc2017_i
[x] 200 OK
[*] save cookie to: /home/user/.local/share/onlinejudge/cookie.jar
[+] success:
int n, m, k; cin >> n >> m >> k;
vector<int> x(2); for (int i = 0; i < 2; ++ i) cin >> x[i];
vector<int> l(m), r(m); for (int i = 0; i < m; ++ i) cin >> l[i] >> r[i];

pip3 install online-judge-toolsでいれたらエラーがでます.

% oj download http://agc001.contest.atcoder.jp/tasks/agc001_a                                                    [~]+[master]
Traceback (most recent call last):
  File "/usr/local/bin/oj", line 2, in <module>
    import onlinejudge.implementation.main
  File "/usr/local/lib/python3.5/site-packages/onlinejudge/implementation/main.py", line 6, in <module>
    from onlinejudge.implementation.command.download import download
ImportError: No module named 'onlinejudge.implementation.command'

環境はmacOSX です.

テストの拡充

一番重要なdowloadに関するテストはちゃんと動いてるので緊急性は低い
しかしひとかたまりの大きなケース扱いになってるの汚いし、他の機能のテストが手動なのはかなり良くない

Yukicoder No. 3016, 成功してもよさそうなgenerate-scannerの失敗

$ oj g/s http://yukicoder.me/problems/no/3016                                                                                                                                            ~contest/yuki/3016
[!] This feature is experimental.
[x] problem recognized: <onlinejudge.yukicoder.YukicoderProblem object at 0x7f4a553c12b0>: http://yukicoder.me/problems/no/3016
[*] load cookie from: /home/user/.local/share/onlinejudge/cookie.jar
[x] GET: https://yukicoder.me/problems/no/3016
[x] 200 OK
[*] save cookie to: /home/user/.local/share/onlinejudge/cookie.jar
[ERROR] somethin wrong
Traceback (most recent call last):
  File "/usr/local/bin/oj", line 6, in <module>
    onlinejudge.implementation.main.main(args=sys.argv[1:])
  File "/usr/local/lib/python3.5/dist-packages/onlinejudge/implementation/main.py", line 273, in main
    generate_scanner(args)
  File "/usr/local/lib/python3.5/dist-packages/onlinejudge/implementation/command/generate_scanner.py", line 182, in generate_scanner
    it = tokenize(it)
  File "/usr/local/lib/python3.5/dist-packages/onlinejudge/implementation/command/generate_scanner.py", line 25, in tokenize
    assert False
AssertionError

generate randam cases

制約まで解析できればランダムケースの生成ができる やりたい

test for floating points

欲しいんだけど誤差の指定の方法とか出力フォーマットどうなるのとかの調査が必要

memo: nanやinfには注意が必要だったはず

pip install . に失敗する

https://travis-ci.org/kmyk/online-judge-tools/builds/288689200

$ pip install .
Processing /home/travis/build/kmyk/online-judge-tools
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-eiiyuaru-build/setup.py", line 3, in <module>
        from onlinejudge.implementation.version import __author__, __email__, __license__, __url__, __version__
      File "/tmp/pip-eiiyuaru-build/onlinejudge/__init__.py", line 3, in <module>
        import onlinejudge.atcoder
      File "/tmp/pip-eiiyuaru-build/onlinejudge/atcoder.py", line 5, in <module>
        import onlinejudge.dispatch
      File "/tmp/pip-eiiyuaru-build/onlinejudge/dispatch.py", line 2, in <module>
        import onlinejudge.implementation.logging as log
      File "/tmp/pip-eiiyuaru-build/onlinejudge/implementation/logging.py", line 12, in <module>
        import colorama
    ImportError: No module named 'colorama'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-eiiyuaru-build/

AtCoder への提出に失敗する

デグレっぽい

[*] load cookie from: /home/user/.local/share/onlinejudge/cookie.jar
[x] GET: http://agc014.contest.atcoder.jp/submit
[x] 200 OK
[x] sleep(3.00)
[x] GET: http://agc014.contest.atcoder.jp/submit
[x] 200 OK
[x] GET: http://agc014.contest.atcoder.jp/submit
[x] 200 OK
[x] GET: http://agc014.contest.atcoder.jp/tasks/agc014_e
[x] 200 OK
[x] POST: https://agc014.contest.atcoder.jp/submit?task_id=2373
[x] 200 OK
[+] success: result: https://agc014.contest.atcoder.jp/submissions/me#30393
Traceback (most recent call last):
  File "/usr/local/bin/oj", line 6, in <module>
    onlinejudge.implementation.main.main(args=sys.argv[1:])
  File "/usr/local/lib/python3.5/dist-packages/onlinejudge/implementation/main.py", line 267, in main
    submit(args)
  File "/usr/local/lib/python3.5/dist-packages/onlinejudge/implementation/command/submit.py", line 48, in submit
    submission = problem.submit(code, language=args.language, session=sess)
  File "/usr/local/lib/python3.5/dist-packages/onlinejudge/atcoder.py", line 234, in submit
    return AtCoderSubmission.from_url(resp.url, problem_id=self.problem_id)
TypeError: from_url() got an unexpected keyword argument 'problem_id'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.