This repository has been archived by the owner on Jan 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
judge.py
97 lines (78 loc) · 2.26 KB
/
judge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class RunInfo:
def __init__(self, time=0, mem=0):
self.time = time
self.mem = mem
def __str__(self):
return 'Time: {time}s, Mem: {mem} KiB'.format(
time=self.time / 1000.0, mem=self.mem
)
def __add__(self, n):
return RunInfo(self.time + n.time, self.mem + n.mem)
def __iadd__(self, n):
self.time += n.time
self.mem += n.mem
return self
def __truediv__(self, n):
return RunInfo(self.time / n, self.mem // n)
class JudgeResult:
# 0: No exceptions
AC = 0
WA = 1
OK = 99
# 100: Runtime exceptions
RE = 100
TLE = 101
MLE = 102
FSE = 103
# 200: Compilation exceptions
CE = 200
FTE = 201
# 800: Internal exceptions
IE = 800
AV = 801
# 900: Miscellaneous
UNKNOWN = 999
INFO = {
AC: 'Accepted',
WA: 'Wrong answer',
OK: 'OK',
RE: 'Runtime error',
MLE: 'Memory limit exceeded',
TLE: 'Time limit exceeded',
FSE: 'File size error',
CE: 'Compile error',
FTE: 'Invalid file type',
IE: 'Internal error',
# AV: 'Access violation', don't tell this
AV: 'Runtime error',
UNKNOWN: 'Unknown error'
}
@staticmethod
def stringBase(res):
return JudgeResult.INFO.get(res, 'Unknown result')
@staticmethod
def stringBasePrettify(res):
if res in set((JudgeResult.AC, JudgeResult.OK)):
return '\x1B[1;32m' + JudgeResult.stringBase(res) + '\x1B[0m'
else:
return '\x1B[1;31m' + JudgeResult.stringBase(res) + '\x1B[0m'
@staticmethod
def isOK(s):
OKcode = [JudgeResult.AC, JudgeResult.WA, JudgeResult.OK]
try:
return s.value in OKcode
except AttributeError:
return s in OKcode
def __init__(self, value, res=None):
self.value = value
self.res = res
def __str__(self):
return JudgeResult.stringBase(self.value)
def pretty(self):
return JudgeResult.stringBasePrettify(self.value)
class JudgeError(Exception, JudgeResult):
def __init__(self, value, res=None):
self.value = value
self.res = res
def __str__(self):
return JudgeResult.stringBase(self.value)