judge: 支持对不同语言设置不同时限

This commit is contained in:
undefined committed 2020-10-31 12:00:42 +08:00
1 parent c553f204ad
commit 3fc5612ca3
4 files changed
+22 -6

No files matched your search

+1 -1
View File
@@ -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",
+8 -3
View File
@@ -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<Execute> {
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');
}
+11
View File
@@ -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,
}
+2 -2
View File
@@ -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;