-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjudger.py
More file actions
47 lines (43 loc) · 1.53 KB
/
judger.py
File metadata and controls
47 lines (43 loc) · 1.53 KB
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
import sys, re, subprocess as s
import os
def judge(filename):
sample_in_list = []
sample_out_list = []
for file in os.listdir("judge"):
if file.endswith('.in') and os.path.isfile("judge/%sout" % file[:-2]):
sample_in_list.append(os.path.join("judge", file))
sample_out_list.append(os.path.join("judge", file[:-2] + "out"))
return "python vis.py %s" % ''.join(_judge(filename, sample_in_list, sample_out_list))
def _judge(filename, sample_in_list: list, sample_out_list: list):
res = ["A"] * len(sample_in_list)
for i, sample_in in enumerate(sample_in_list):
sample_out = sample_out_list[i]
sout = []; out = []
with open(sample_out) as fr:
for line in fr.read().split('\n'):
l = line.lstrip().rstrip()
if l:
sout.append(l)
with open(sample_in) as fr:
processedIn = s.Popen("%s %s" % ("type" if sys.platform == "win32" else "cat", sample_in), shell=True, stdout=s.PIPE)
o = s.Popen("%s --timeout 1000 -q %s" % (os.path.join("judger", "procgov"), filename), shell=True, stdin=processedIn.stdout, stdout=s.PIPE)
r = o.stdout.read().decode()
if not r:
res[i] = "T"
continue
o2 = s.Popen("%s --maxmem 256M -q %s" % (os.path.join("judger", "procgov"), filename), shell=True, stdin=processedIn.stdout, stdout=s.PIPE)
r2 = o2.stdout.read().decode()
if not r2:
res[i] = "M"
continue
if o.returncode or o2.returncode:
res[i] = "R"
continue
for line in r.split('\n'):
l = line.lstrip().rstrip()
if l:
out.append(l)
print(out)
if sout != out:
res[i] = "W"
return res