OnlineJudge/judge/languages.py

236 lines
5.9 KiB
Python
Raw Permalink Normal View History

2019-03-13 09:57:59 +00:00
from problem.models import ProblemIOMode
2018-03-23 11:39:46 +00:00
default_env = ["LANG=en_US.UTF-8", "LANGUAGE=en_US:en", "LC_ALL=en_US.UTF-8"]
_c_lang_config = {
2017-11-26 05:30:07 +00:00
"template": """//PREPEND BEGIN
2017-02-06 08:41:14 +00:00
#include <stdio.h>
//PREPEND END
//TEMPLATE BEGIN
int add(int a, int b) {
2024-01-29 08:05:19 +00:00
// code
2017-02-06 08:41:14 +00:00
}
//TEMPLATE END
2017-11-26 05:30:07 +00:00
//APPEND BEGIN
2017-02-06 08:41:14 +00:00
int main() {
2024-01-29 08:05:19 +00:00
printf("%d\n", add(1, 2));
2017-02-06 08:41:14 +00:00
return 0;
}
//APPEND END""",
"compile": {
"src_name": "main.c",
"exe_name": "main",
"max_cpu_time": 3000,
2018-05-16 17:28:08 +00:00
"max_real_time": 10000,
"max_memory": 256 * 1024 * 1024,
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c17 {src_path} -lm -o {exe_path}",
},
"run": {
"command": "{exe_path}",
2019-03-13 09:57:59 +00:00
"seccomp_rule": {ProblemIOMode.standard: "c_cpp", ProblemIOMode.file: "c_cpp_file_io"},
2018-03-23 11:39:46 +00:00
"env": default_env
}
}
_c_lang_spj_compile = {
"src_name": "spj-{spj_version}.c",
"exe_name": "spj-{spj_version}",
"max_cpu_time": 3000,
2018-05-16 17:28:08 +00:00
"max_real_time": 10000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c17 {src_path} -lm -o {exe_path}"
}
_c_lang_spj_config = {
"exe_name": "spj-{spj_version}",
"command": "{exe_path} {in_file_path} {user_out_file_path}",
"seccomp_rule": "c_cpp"
}
_cpp_lang_config = {
2017-11-26 05:30:07 +00:00
"template": """//PREPEND BEGIN
#include <iostream>
//PREPEND END
//TEMPLATE BEGIN
int add(int a, int b) {
2024-01-29 08:05:19 +00:00
// code
2017-11-26 05:30:07 +00:00
}
//TEMPLATE END
//APPEND BEGIN
int main() {
2024-01-29 08:05:19 +00:00
std::cout << add(1, 2) << std::endl;
2017-11-26 05:30:07 +00:00
return 0;
}
//APPEND END""",
"compile": {
"src_name": "main.cpp",
"exe_name": "main",
2019-09-22 06:55:17 +00:00
"max_cpu_time": 10000,
"max_real_time": 20000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++20 {src_path} -lm -o {exe_path}",
},
"run": {
"command": "{exe_path}",
2019-03-28 02:48:55 +00:00
"seccomp_rule": {ProblemIOMode.standard: "c_cpp", ProblemIOMode.file: "c_cpp_file_io"},
2018-03-23 11:39:46 +00:00
"env": default_env
}
}
2017-01-26 09:14:40 +00:00
_cpp_lang_spj_compile = {
"src_name": "spj-{spj_version}.cpp",
"exe_name": "spj-{spj_version}",
2019-09-22 06:55:17 +00:00
"max_cpu_time": 10000,
"max_real_time": 20000,
2017-01-26 09:14:40 +00:00
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c++20 {src_path} -lm -o {exe_path}"
2017-01-26 09:14:40 +00:00
}
_cpp_lang_spj_config = {
"exe_name": "spj-{spj_version}",
"command": "{exe_path} {in_file_path} {user_out_file_path}",
"seccomp_rule": "c_cpp"
}
_java_lang_config = {
2017-12-01 13:53:13 +00:00
"template": """//PREPEND BEGIN
2024-01-29 08:05:19 +00:00
class Main {
2017-12-01 13:53:13 +00:00
//PREPEND END
//TEMPLATE BEGIN
2024-01-29 08:05:19 +00:00
static int add(int a, int b) {
// code
}
2017-12-01 13:53:13 +00:00
//TEMPLATE END
//APPEND BEGIN
2024-01-29 08:05:19 +00:00
public static void main(String [] args) {
System.out.println(add(1, 2));
}
}
2017-12-01 13:53:13 +00:00
//APPEND END""",
"compile": {
"src_name": "Main.java",
"exe_name": "Main",
2019-09-22 06:55:17 +00:00
"max_cpu_time": 5000,
"max_real_time": 10000,
"max_memory": -1,
"compile_command": "/usr/bin/javac {src_path} -d {exe_dir}"
},
"run": {
"command": "/usr/bin/java -cp {exe_dir} -XX:MaxRAM={max_memory}k Main",
"seccomp_rule": None,
2018-03-23 11:39:46 +00:00
"env": default_env,
"memory_limit_check_only": 1
}
}
_py3_lang_config = {
2017-12-01 13:53:13 +00:00
"template": """//PREPEND BEGIN
//PREPEND END
//TEMPLATE BEGIN
2024-01-29 08:05:19 +00:00
def add(a, b):
# code
2017-12-01 13:53:13 +00:00
//TEMPLATE END
//APPEND BEGIN
2024-01-29 08:05:19 +00:00
print(add(1, 2))
2017-12-01 13:53:13 +00:00
//APPEND END""",
"compile": {
"src_name": "solution.py",
"exe_name": "solution.py",
"max_cpu_time": 3000,
2018-05-16 17:28:08 +00:00
"max_real_time": 10000,
"max_memory": 128 * 1024 * 1024,
"compile_command": "/usr/bin/python3 -m py_compile {src_path}",
},
"run": {
"command": "/usr/bin/python3 -BS {exe_path}",
"seccomp_rule": "general",
"env": default_env
}
}
2020-07-08 01:46:08 +00:00
_go_lang_config = {
"template": """//PREPEND BEGIN
2024-01-29 08:05:19 +00:00
package main
import "fmt"
2020-07-08 01:46:08 +00:00
//PREPEND END
//TEMPLATE BEGIN
2024-01-29 08:05:19 +00:00
func add(a int, b int) int {
// code
}
2020-07-08 01:46:08 +00:00
//TEMPLATE END
//APPEND BEGIN
2024-01-29 08:05:19 +00:00
func main() {
fmt.Println(add(1, 2))
}
2020-07-08 01:46:08 +00:00
//APPEND END""",
"compile": {
"src_name": "main.go",
"exe_name": "main",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/go build -o {exe_path} {src_path}",
2021-09-28 07:43:38 +00:00
"env": ["GOCACHE=/tmp", "GOPATH=/tmp", "GOMAXPROCS=1"] + default_env
2020-07-08 01:46:08 +00:00
},
"run": {
"command": "{exe_path}",
2021-09-28 07:43:38 +00:00
"seccomp_rule": "golang",
"env": ["GOMAXPROCS=1"] + default_env,
2021-09-28 07:43:38 +00:00
"memory_limit_check_only": 1
}
}
_node_lang_config = {
"template": """//PREPEND BEGIN
//PREPEND END
//TEMPLATE BEGIN
2024-01-29 08:05:19 +00:00
function add(a, b) {
// code
}
2021-09-28 07:43:38 +00:00
//TEMPLATE END
//APPEND BEGIN
2024-01-29 08:05:19 +00:00
console.log(add(1, 2))
2021-09-28 07:43:38 +00:00
//APPEND END""",
"compile": {
"src_name": "main.js",
"exe_name": "main.js",
"max_cpu_time": 3000,
"max_real_time": 5000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/node --check {src_path}",
"env": default_env
},
"run": {
"command": "/usr/bin/node {exe_path}",
"seccomp_rule": "node",
"env": default_env,
2020-07-08 01:46:08 +00:00
"memory_limit_check_only": 1
}
}
languages = [
{"config": _c_lang_config, "name": "C", "description": "GCC 13", "content_type": "text/x-csrc",
"spj": {"compile": _c_lang_spj_compile, "config": _c_lang_spj_config}},
{"config": _cpp_lang_config, "name": "C++", "description": "GCC 13", "content_type": "text/x-c++src",
"spj": {"compile": _cpp_lang_spj_compile, "config": _cpp_lang_spj_config}},
{"config": _java_lang_config, "name": "Java", "description": "Temurin 21", "content_type": "text/x-java"},
{"config": _py3_lang_config, "name": "Python3", "description": "Python 3.12", "content_type": "text/x-python"},
{"config": _go_lang_config, "name": "Golang", "description": "Golang 1.22", "content_type": "text/x-go"},
{"config": _node_lang_config, "name": "JavaScript", "description": "Node.js 20", "content_type": "text/javascript"},
]