forked from huaizhongoi/syzoj
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
479 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
interface TestcaseDetails { | ||
type: TestcaseResultType; | ||
time: number; | ||
memory: number; | ||
input?: FileContent; | ||
output?: FileContent; // Output in test data | ||
scoringRate: number; // e.g. 0.5 | ||
userOutput?: string; | ||
userError?: string; | ||
spjMessage?: string; | ||
systemMessage?: string; | ||
} | ||
|
||
interface TestcaseResult { | ||
status: TaskStatus; | ||
result?: TestcaseDetails; | ||
errorMessage?: string; | ||
} | ||
|
||
interface SubtaskResult { | ||
score?: number; | ||
cases: TestcaseResult[]; | ||
} | ||
|
||
declare enum ErrorType { | ||
SystemError, | ||
TestDataError | ||
} | ||
|
||
interface CompilationResult { | ||
status: TaskStatus; | ||
message?: string; | ||
} | ||
|
||
interface JudgeResult { | ||
subtasks?: SubtaskResult[]; | ||
} | ||
|
||
interface OverallResult { | ||
error?: ErrorType; | ||
systemMessage?: string; | ||
compile?: CompilationResult; | ||
judge?: JudgeResult; | ||
} | ||
|
||
declare enum TaskStatus { | ||
Waiting = 0, | ||
Running = 1, | ||
Done = 2, | ||
Failed = 3, | ||
Skipped = 4 | ||
} | ||
|
||
declare enum TestcaseResultType { | ||
Accepted = 1, | ||
WrongAnswer = 2, | ||
PartiallyCorrect = 3, | ||
MemoryLimitExceeded = 4, | ||
TimeLimitExceeded = 5, | ||
OutputLimitExceeded = 6, | ||
FileError = 7, // The output file does not exist | ||
RuntimeError = 8, | ||
JudgementFailed = 9, // Special Judge or Interactor fails | ||
InvalidInteraction = 10 | ||
} | ||
|
||
interface FileContent { | ||
content: string, | ||
name: string | ||
} | ||
|
||
declare enum ProgressReportType { | ||
Started = 1, | ||
Compiled = 2, | ||
Progress = 3, | ||
Finished = 4, | ||
Reported = 5, | ||
} | ||
|
||
interface ProgressReportData { | ||
taskId: string; | ||
type: ProgressReportType; | ||
progress: OverallResult | CompilationResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const luogu = require("./vjudge/lugou"); | ||
|
||
module.exports = function vjudge(judge_state, problem, onProgress) { | ||
if (problem.type === "vjudge:luogu") return luogu(judge_state, problem, onProgress); | ||
}; | ||
|
||
module.exports.languages = { | ||
luogu: luogu.languages | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/// <reference types="../interfaces" /> | ||
|
||
const { LuoguOpenApiClient } = require("@menci/luogu-openapi"); | ||
|
||
/** | ||
* @type {LuoguOpenApiClient} | ||
*/ | ||
let client; | ||
|
||
const onUpstreamProgressCallbacks = new Map(); | ||
|
||
/** | ||
* @param {string} trackId | ||
* @param {JudgeRecord} data | ||
*/ | ||
function onJudgeProgress(trackId, data) { | ||
const f = onUpstreamProgressCallbacks.get(trackId); | ||
if (!f) return; | ||
f(trackId, data); | ||
} | ||
|
||
/** | ||
* @param {(progress: ProgressReportData) => void} onProgress | ||
*/ | ||
module.exports = async function vjudge(judge_state, problem, onProgress) { | ||
if (!client) { | ||
client = new LuoguOpenApiClient(syzoj.config.luogu_openapi_token, onJudgeProgress); | ||
} | ||
|
||
/** | ||
* @param {JudgeRecord} data | ||
*/ | ||
function onUpstreamProgress(trackId, data) { | ||
const compile = data.compile ? { | ||
status: data.compile.success ? /* Done */ 2 : /* Failed */ 3, | ||
message: data.compile.message | ||
} : null; | ||
const judge = data.compile && data.compile.success && data.judge ? { | ||
subtasks: data.judge.subtasks.map(subtask => ({ | ||
score: subtask.score, | ||
cases: subtask.cases.map(testcase => { | ||
const status = { | ||
[/* Waiting */ 0]: /* Waiting */ 0, | ||
[/* Judging */ 1]: /* Running */ 1, | ||
[/* CompileError */ 2]: /* Failed */ 3, | ||
[/* OutputLimitExceeded */ 3]: /* Done */ 2, | ||
[/* MemoryLimitExceeded */ 4]: /* Done */ 2, | ||
[/* TimeLimitExceeded */ 5]: /* Done */ 2, | ||
[/* WrongAnswer */ 6]: /* Done */ 2, | ||
[/* RuntimeError */ 7]: /* Done */ 2, | ||
[/* Invalid */ 11]: /* Skipped */ 4, | ||
[/* Accepted */ 12]: /* Done */ 2, | ||
[/* OverallUnaccepted */ 14]: /* Done */ 2 | ||
}[testcase.status]; | ||
return { | ||
status: status, | ||
result: status === /* Done */ 2 ? { | ||
type: { | ||
[/* Waiting */ 0]: -1, | ||
[/* Judging */ 1]: -1, | ||
[/* CompileError */ 2]: -1, | ||
[/* OutputLimitExceeded */ 3]: /* OutputLimitExceeded */ 6, | ||
[/* MemoryLimitExceeded */ 4]: /* MemoryLimitExceeded */ 4, | ||
[/* TimeLimitExceeded */ 5]: /* TimeLimitExceeded */ 5, | ||
[/* WrongAnswer */ 6]: /* WrongAnswer */ 2, | ||
[/* RuntimeError */ 7]: /* RuntimeError */ 8, | ||
[/* Invalid */ 11]: -1, | ||
[/* Accepted */ 12]: /* Accepted */ 1, | ||
[/* OverallUnaccepted */ 14]: /* PartiallyCorrect */ 3 | ||
}[testcase.status], | ||
time: testcase.time, | ||
memory: testcase.memory, | ||
scoringRate: testcase.score / 100, | ||
spjMessage: testcase.description, | ||
systemMessage: JSON.stringify(testcase, null, 2) | ||
} : null | ||
} | ||
}) | ||
})) | ||
} : null; | ||
let finished = false; | ||
if (compile && judge) { | ||
finished = ![/* Waiting */ 1, /* Judging */ 2].includes(data.judge.status); | ||
onProgress({ | ||
taskId: judge_state.task_id, | ||
type: finished ? /* Finished */ 4 : /* Progress */ 3, | ||
progress: { compile: compile, judge: judge } | ||
}); | ||
} else if (compile) { | ||
finished = !data.compile.success; | ||
if (finished) { | ||
onProgress({ | ||
taskId: judge_state.task_id, | ||
type: /* Finished */ 4, | ||
progress: { compile: compile } | ||
}); | ||
} else { | ||
onProgress({ | ||
taskId: judge_state.task_id, | ||
type: /* Compiled */ 2, | ||
progress: compile | ||
}); | ||
} | ||
} | ||
|
||
if (finished) onUpstreamProgressCallbacks.delete(trackId); | ||
} | ||
|
||
try { | ||
const trackId = await client.submit({ | ||
pid: problem.vjudge_config, | ||
lang: judge_state.language, | ||
o2: true, | ||
code: judge_state.code | ||
}); | ||
onUpstreamProgressCallbacks.set(trackId, onUpstreamProgress); | ||
} catch (e) { | ||
onProgress({ | ||
taskId: judge_state.task_id, | ||
type: /* Finished */ 4, | ||
progress: { | ||
error: /* SystemError */ 0, | ||
systemMessage: e.stack | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
const languages = { | ||
"cxx/noi/202107": "ISO C++14 w/ GCC 9.3.0", | ||
"cxx/98/gcc": "ISO C++98 (GCC)", | ||
"cxx/11/gcc": "ISO C++11 (GCC)", | ||
"cxx/14/gcc": "ISO C++14 (GCC)", | ||
"cxx/17/gcc": "ISO C++17 (GCC)", | ||
"cxx/20/gcc ": "ISO C++20 (GCC)", | ||
"c/99/gcc": "ISO C99 (GCC)", | ||
"python3/c": "Python 3 (CPython)", | ||
"python3/py": "Python 3 (PyPy)", | ||
"pascal/fpc": "Pascal", | ||
"rust/rustc": "Rust nightly (rustc)", | ||
"haskell/ghc": "Haskell (GHC)", | ||
"go": "Go", | ||
"php": "PHP", | ||
"ruby": "Ruby", | ||
"js/node/lts": "Node.js LTS", | ||
"perl": "Perl", | ||
"java/8": "Java 8", | ||
"kotlin/jvm": "Kotlin/JVM", | ||
"scala": "Scala", | ||
}; | ||
|
||
module.exports.languages = {}; | ||
let i = 0; | ||
for (const l in languages) { | ||
let base = l.split("/")[0]; | ||
if (base === "cxx") base = "cpp"; | ||
if (base.startsWith("python")) base = "python"; | ||
const lang = { | ||
index: i++, | ||
show: languages[l], | ||
highlight: base, | ||
editor: base | ||
}; | ||
if (base === "cpp" || base === "c") lang.format = base; | ||
module.exports.languages[l] = lang; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.