|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import argparse |
| 4 | +import subprocess |
| 5 | +import time |
| 6 | + |
| 7 | +import colorama |
| 8 | + |
| 9 | +import codeforces |
| 10 | + |
| 11 | +colorama.init(autoreset=True) |
| 12 | + |
| 13 | +def main(argv=None): |
| 14 | + parser = argparse.ArgumentParser() |
| 15 | + |
| 16 | + parser.add_argument('contestId', type=int, |
| 17 | + help=("Id of the contest. It is not the round number. " |
| 18 | + "It can be seen in contest URL.")) |
| 19 | + |
| 20 | + parser.add_argument('index', type=str, |
| 21 | + help=("A letter or a letter followed by a digit, that " |
| 22 | + "represent a problem index in a contest.")) |
| 23 | + |
| 24 | + parser.add_argument('program', type=str, |
| 25 | + help="Path to executable that needs to be tested") |
| 26 | + |
| 27 | + parser.add_argument('-t', '--timeout', type=int, default=10, |
| 28 | + help=("Timeout for program in seconds, -1 for no time " |
| 29 | + "limit (default: 10)")) |
| 30 | + |
| 31 | + parser.add_argument('-g', '--gym', action='store_true', |
| 32 | + help=("If true open gym contest instead of regular " |
| 33 | + "contest. (default: false)")) |
| 34 | + |
| 35 | + if argv: |
| 36 | + args = parser.parse_args(argv) |
| 37 | + else: |
| 38 | + args = parser.parse_args() |
| 39 | + |
| 40 | + args.timeout = None if args.timeout == -1 else args.timeout |
| 41 | + |
| 42 | + title, time_limit, memory_limit, sample_tests = codeforces.problem.get_info( |
| 43 | + args.contestId, args.index, gym=args.gym |
| 44 | + ) |
| 45 | + |
| 46 | + print(title) |
| 47 | + print("time limit per test:", time_limit) |
| 48 | + print("memory limit per test:", memory_limit) |
| 49 | + |
| 50 | + print() |
| 51 | + |
| 52 | + for inp, ans in sample_tests: |
| 53 | + start = time.time() |
| 54 | + |
| 55 | + out = subprocess.run( |
| 56 | + args.program, |
| 57 | + input=inp.encode('utf-8'), |
| 58 | + capture_output=True, |
| 59 | + timeout=args.timeout |
| 60 | + ).stdout.decode('utf-8') |
| 61 | + |
| 62 | + time_used = time.time() - start |
| 63 | + |
| 64 | + print('-' * 80, '\n') |
| 65 | + |
| 66 | + print('Time: %d ms\n' % (time_used * 1000)) |
| 67 | + |
| 68 | + print(colorama.Style.BRIGHT + 'Input') |
| 69 | + print(inp) |
| 70 | + |
| 71 | + print(colorama.Style.BRIGHT + "Participant's output") |
| 72 | + print(out) |
| 73 | + |
| 74 | + print(colorama.Style.BRIGHT + "Jury's answer") |
| 75 | + print(ans) |
0 commit comments