forked from LanceLRQ/deer-executor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
135 lines (120 loc) · 3.56 KB
/
Copy pathmain.go
File metadata and controls
135 lines (120 loc) · 3.56 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Deer executor
* (C) 2019 LanceLRQ
*
* This code is licenced under the GPLv3.
*/
package deer_executor
import (
"bytes"
"encoding/json"
"fmt"
)
const (
JUDGE_FLAG_AC int = 0 //0 Accepted
JUDGE_FLAG_PE int = 1 //1 Presentation Error
JUDGE_FLAG_TLE int = 2 //2 Time Limit Exceeded
JUDGE_FLAG_MLE int = 3 //3 Memory Limit Exceeded
JUDGE_FLAG_WA int = 4 //4 Wrong Answer
JUDGE_FLAG_RE int = 5 //5 Runtime Error
JUDGE_FLAG_OLE int = 6 //6 Output Limit Exceeded
JUDGE_FLAG_CE int = 7 //7 Compile Error
JUDGE_FLAG_SE int = 8 //8 System Error
JUDGE_FLAG_SPJ_TIME_OUT int = 10 // 10 Special Judger Time OUT
JUDGE_FLAG_SPJ_ERROR int = 11 // 11 Special Judger ERROR
JUDGE_FLAG_SPJ_REQUIRE_CHECK int = 12 // 12 Special Judger Finish, Need Standard Checkup
JUDGE_FILE_SIZE_LIMIT = 200 * 1024 * 1024 // 200MB
)
const (
SPECIAL_JUDGE_MODE_DISABLED = 0
SPECIAL_JUDGE_MODE_CHECKER = 1
SPECIAL_JUDGE_MODE_INTERACTIVE = 2
SPECIAL_JUDGE_TIME_LIMIT = 10 * 1000 // ms
SPECIAL_JUDGE_MEMORY_LIMIT = 256 * 1024 // kb
)
type JudgeResult struct {
JudgeResult int // Judge result flag number
TimeUsed int // Maximum time used
MemoryUsed int // Maximum memory used
ReSignum int // Runtime error signal number
SameLines int // sameLines when WA
TotalLines int // totalLines when WA
SeInfo string // SeInfo When System Error
CeInfo string // CeInfo When CeInfo
}
type JudgeOption struct {
Commands [] string // Executable program commands
TestCaseIn string
TestCaseOut string
ProgramOut string
ProgramError string
TimeLimit int // Time limit (ms)
MemoryLimit int // Memory limit (kb)
FileSizeLimit int // File Size Limit (kb)
Uid int // User id (optional)
SpecialJudge struct {
Mode int // Mode
Checker string // Checker file path
RedirectStd bool // Redirect target program's Stdout to checker's Stdin
TimeLimit int // Time limit (ms)
MemoryLimit int // Memory limit (kb)
Stdout string // checker's stdout
Stderr string // checker's stderr
}
}
func (conf *JudgeResult) String() string {
b, err := json.Marshal(*conf)
if err != nil {
return fmt.Sprintf("%+v", *conf)
}
var out bytes.Buffer
err = json.Indent(&out, b, "", " ")
if err != nil {
return fmt.Sprintf("%+v", *conf)
}
return out.String()
}
// 这个函数实现了判题的基本用法,考虑到实际情况不一定会使用这个函数,你可以模仿这个函数的写法来调用自己需要的功能
func Judge(options JudgeOption) (*JudgeResult, error) {
judgeResult := new(JudgeResult)
if options.SpecialJudge.Mode == SPECIAL_JUDGE_MODE_INTERACTIVE {
err := InteractiveChecker(options, judgeResult, nil)
if err != nil {
return nil, err
}
// Text Diff
if judgeResult.JudgeResult == JUDGE_FLAG_SPJ_REQUIRE_CHECK {
err = DiffText(options, judgeResult)
if err != nil {
return nil, err
}
}
} else {
// Run Program
err := RunProgram(options, judgeResult, nil)
if err != nil {
return nil, err
}
if options.SpecialJudge.Mode == SPECIAL_JUDGE_MODE_CHECKER && judgeResult.JudgeResult == JUDGE_FLAG_AC {
err := CustomChecker(options, judgeResult, nil)
if err != nil {
return nil, err
}
// Text Diff
if judgeResult.JudgeResult == JUDGE_FLAG_SPJ_REQUIRE_CHECK {
err = DiffText(options, judgeResult)
if err != nil {
return nil, err
}
}
} else {
// Text Diff
if judgeResult.JudgeResult == JUDGE_FLAG_AC {
err = DiffText(options, judgeResult)
if err != nil {
return nil, err
}
}
}
}
return judgeResult, nil
}