From 3fc5612ca35c4bf1373e0a2bfc3eb3c34b52f725 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 31 Oct 2020 12:00:42 +0800 Subject: [PATCH] =?UTF-8?q?judge:=20=E6=94=AF=E6=8C=81=E5=AF=B9=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E8=AF=AD=E8=A8=80=E8=AE=BE=E7=BD=AE=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/compile.ts | 11 ++++++++--- packages/hydrojudge/src/interface.ts | 11 +++++++++++ packages/hydrojudge/src/judge/default.ts | 4 ++-- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 packages/hydrojudge/src/interface.ts diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 2e1341167..9b5153f1c 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.1.17", + "version": "2.1.18", "main": "package.json", "author": "masnn", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/compile.ts b/packages/hydrojudge/src/compile.ts index 5b8902455..1f2d8af37 100644 --- a/packages/hydrojudge/src/compile.ts +++ b/packages/hydrojudge/src/compile.ts @@ -3,10 +3,11 @@ import * as STATUS from './status'; import { run, del } from './sandbox'; import { CompileError, SystemError } from './error'; import { compilerText } from './utils'; +import { Execute } from './interface'; export = async function compile( lang: string, code: string, target: string, copyIn: any, next?: Function, -) { +): Promise { const LANGS = global.Hydro ? yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs')) : require('./config').LANGS; @@ -26,10 +27,14 @@ export = async function compile( if (!fileIds[target]) throw new CompileError({ stderr: '没有找到可执行文件' }); if (next) next({ compiler_text: compilerText(stdout, stderr) }); f[target] = { fileId: fileIds[target] }; - return { execute: info.execute, copyIn: f, clean: () => del(fileIds[target]) }; + return { + execute: info.execute, copyIn: f, clean: () => del(fileIds[target]), time: info.time || 1, + }; } if (info.type === 'interpreter') { f[target] = { content: code }; - return { execute: info.execute, copyIn: f, clean: () => Promise.resolve() }; + return { + execute: info.execute, copyIn: f, clean: () => Promise.resolve(), time: info.time || 1, + }; } throw new SystemError('Unknown language type'); } diff --git a/packages/hydrojudge/src/interface.ts b/packages/hydrojudge/src/interface.ts new file mode 100644 index 000000000..853d16226 --- /dev/null +++ b/packages/hydrojudge/src/interface.ts @@ -0,0 +1,11 @@ +export interface SFile { + src?: string, + content?: string, + fileId?: string, +} +export interface Execute { + execute: string, + clean: Function, + copyIn: Record, + time?: number, +} diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index f5ed41279..70b3f8cd0 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -33,7 +33,7 @@ function judgeCase(c) { stderr, copyIn, copyOut, - time_limit_ms: ctxSubtask.subtask.time_limit_ms, + time_limit_ms: ctxSubtask.subtask.time_limit_ms * ctx.execute.time, memory_limit_mb: ctxSubtask.subtask.memory_limit_mb, }, ); @@ -45,7 +45,7 @@ function judgeCase(c) { let message = ''; let score = 0; if (status === STATUS.STATUS_ACCEPTED) { - if (time_usage_ms > ctxSubtask.subtask.time_limit_ms) { + if (time_usage_ms > ctxSubtask.subtask.time_limit_ms * ctx.execute.time) { status = STATUS.STATUS_TIME_LIMIT_EXCEEDED; } else if (memory_usage_kb > ctxSubtask.subtask.memory_limit_mb * 1024) { status = STATUS.STATUS_MEMORY_LIMIT_EXCEEDED;