-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcpp.py
More file actions
31 lines (27 loc) · 1.29 KB
/
cpp.py
File metadata and controls
31 lines (27 loc) · 1.29 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
import subprocess
from django.conf import settings
def system(cmd):
return subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
COMPILE_MEMORY_LIMIT = settings.JUDGE_SETTINGS['MINMEMORYSIZE']
LANGUAGE = "C++"
EXT = "cpp"
VERSION = system(["g++", "--version"])[0].split("\n")[0]
ADDITIONAL_FILES = []
def setup(sandbox, source_code):
sandbox.write_file(source_code, "submission.cpp")
compiled = sandbox.run("g++ -O3 submission.cpp -pedantic-errors --std=c++0x -DNDEBUG", stdout=".stdout",
stderr=".stderr", time_limit=10,
memory_limit=COMPILE_MEMORY_LIMIT)
if compiled.split()[0] != "OK":
return {"status": "error",
"message": sandbox.read_file(".stderr")}
#sandbox.run("rm submission.cpp .stdin .stderr")
return {"status": "ok"}
def run(sandbox, input_file, time_limit, memory_limit):
result = sandbox.run("./a.out", stdin=input_file, time_limit=time_limit,
memory_limit=memory_limit, stdout=".stdout", stderr=".stderr")
toks = result.split()
if toks[0] != "OK":
return {"status": "fail", "message": result, "verdict": toks[0] }
return {"status": "ok", "time": toks[1], "memory": toks[2], "output": ".stdout"}