mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: 支持对不同语言设置不同时限
This commit is contained in:
1 parent
c553f204ad
commit
3fc5612ca3
4 files changed
+22
-6
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.1.17",
|
"version": "2.1.18",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "masnn",
|
"author": "masnn",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ import * as STATUS from './status';
|
|||||||
import { run, del } from './sandbox';
|
import { run, del } from './sandbox';
|
||||||
import { CompileError, SystemError } from './error';
|
import { CompileError, SystemError } from './error';
|
||||||
import { compilerText } from './utils';
|
import { compilerText } from './utils';
|
||||||
|
import { Execute } from './interface';
|
||||||
|
|
||||||
export = async function compile(
|
export = async function compile(
|
||||||
lang: string, code: string, target: string, copyIn: any, next?: Function,
|
lang: string, code: string, target: string, copyIn: any, next?: Function,
|
||||||
) {
|
): Promise<Execute> {
|
||||||
const LANGS = global.Hydro
|
const LANGS = global.Hydro
|
||||||
? yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs'))
|
? yaml.safeLoad(await global.Hydro.model.system.get('hydrojudge.langs'))
|
||||||
: require('./config').LANGS;
|
: require('./config').LANGS;
|
||||||
@@ -26,10 +27,14 @@ export = async function compile(
|
|||||||
if (!fileIds[target]) throw new CompileError({ stderr: '没有找到可执行文件' });
|
if (!fileIds[target]) throw new CompileError({ stderr: '没有找到可执行文件' });
|
||||||
if (next) next({ compiler_text: compilerText(stdout, stderr) });
|
if (next) next({ compiler_text: compilerText(stdout, stderr) });
|
||||||
f[target] = { fileId: fileIds[target] };
|
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') {
|
} if (info.type === 'interpreter') {
|
||||||
f[target] = { content: code };
|
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');
|
throw new SystemError('Unknown language type');
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export interface SFile {
|
||||||
|
src?: string,
|
||||||
|
content?: string,
|
||||||
|
fileId?: string,
|
||||||
|
}
|
||||||
|
export interface Execute {
|
||||||
|
execute: string,
|
||||||
|
clean: Function,
|
||||||
|
copyIn: Record<string, SFile>,
|
||||||
|
time?: number,
|
||||||
|
}
|
||||||
@@ -33,7 +33,7 @@ function judgeCase(c) {
|
|||||||
stderr,
|
stderr,
|
||||||
copyIn,
|
copyIn,
|
||||||
copyOut,
|
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,
|
memory_limit_mb: ctxSubtask.subtask.memory_limit_mb,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -45,7 +45,7 @@ function judgeCase(c) {
|
|||||||
let message = '';
|
let message = '';
|
||||||
let score = 0;
|
let score = 0;
|
||||||
if (status === STATUS.STATUS_ACCEPTED) {
|
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;
|
status = STATUS.STATUS_TIME_LIMIT_EXCEEDED;
|
||||||
} else if (memory_usage_kb > ctxSubtask.subtask.memory_limit_mb * 1024) {
|
} else if (memory_usage_kb > ctxSubtask.subtask.memory_limit_mb * 1024) {
|
||||||
status = STATUS.STATUS_MEMORY_LIMIT_EXCEEDED;
|
status = STATUS.STATUS_MEMORY_LIMIT_EXCEEDED;
|
||||||
|
|||||||
Reference in new issue
Block a user