From d6349a70cfb529dff7ba0ac86f024e2174dbe05b Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 2 Mar 2021 23:42:28 +0800 Subject: [PATCH] =?UTF-8?q?judge:=20=E4=BF=AE=E5=A4=8D=20time&mem=20limit?= =?UTF-8?q?=20=E5=9C=A8=E8=87=AA=E5=8A=A8=E6=A8=A1=E5=BC=8F=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrojudge/package.json | 2 +- packages/hydrojudge/src/cases.ts | 32 ++++++++++---------- packages/hydrojudge/src/judge/default.ts | 2 +- packages/hydrojudge/src/judge/interactive.ts | 4 +-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index bbb40cb94..19e9e9c7d 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,7 +1,7 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.4.0", + "version": "2.4.1", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", diff --git a/packages/hydrojudge/src/cases.ts b/packages/hydrojudge/src/cases.ts index c301c8445..31b4816a1 100644 --- a/packages/hydrojudge/src/cases.ts +++ b/packages/hydrojudge/src/cases.ts @@ -67,7 +67,7 @@ const RE1: Re1[] = [ }, ]; -async function read0(folder: string, files: string[], checkFile) { +async function read0(folder: string, files: string[], checkFile, cfg) { const cases = []; for (const file of files) { for (const REG of RE0) { @@ -86,8 +86,8 @@ async function read0(folder: string, files: string[], checkFile) { const config = { count: 0, subtasks: [{ - time_limit_ms: 1000, - memory_limit_mb: 512, + time_limit_ms: parseTimeMS(cfg.time || '1s'), + memory_limit_mb: parseMemoryMB(cfg.memory || '256m'), type: 'sum', cases: [], score: Math.floor(100 / cases.length), @@ -103,8 +103,8 @@ async function read0(folder: string, files: string[], checkFile) { } if (extra < cases.length) { config.subtasks.push({ - time_limit_ms: 1000, - memory_limit_mb: 512, + time_limit_ms: parseTimeMS(cfg.time || '1s'), + memory_limit_mb: parseMemoryMB(cfg.memory || '256m'), type: 'sum', cases: [], score: Math.floor(100 / cases.length) + 1, @@ -121,7 +121,7 @@ async function read0(folder: string, files: string[], checkFile) { return config; } -async function read1(folder: string, files: string[], checkFile) { +async function read1(folder: string, files: string[], checkFile, cfg) { const subtask = {}; const subtasks = []; for (const file of files) { @@ -132,8 +132,8 @@ async function read1(folder: string, files: string[], checkFile) { if (fs.existsSync(path.resolve(folder, c.output))) { if (!subtask[REG.subtask(data)]) { subtask[REG.subtask(data)] = [{ - time_limit_ms: 1000, - memory_limit_mb: 512, + time_limit_ms: parseTimeMS(cfg.time || '1s'), + memory_limit_mb: parseMemoryMB(cfg.memory || '256m'), type: 'min', cases: [c], }]; @@ -164,7 +164,7 @@ async function read1(folder: string, files: string[], checkFile) { return config; } -async function readAutoCases(folder, { next }) { +async function readAutoCases(folder, { next }, cfg) { const config = { checker_type: 'default', count: 0, @@ -183,8 +183,8 @@ async function readAutoCases(folder, { next }) { const outputs = await fs.readdir(path.resolve(folder, 'output')); files.push(...outputs.map((i) => `output/${i}`)); } - let result = await read0(folder, files, checkFile); - if (!result.count) result = await read1(folder, files, checkFile); + let result = await read0(folder, files, checkFile, cfg); + if (!result.count) result = await read1(folder, files, checkFile, cfg); Object.assign(config, result); next({ message: { message: 'Found {0} testcases.', params: [config.count] } }); } catch (e) { @@ -235,8 +235,8 @@ export async function readYamlCases(folder: string, cfg: Dictionary = {}, a for (const c of cfg.cases) { config.count++; config.subtasks[0].cases.push({ - input: checkFile(c.input, 'Cannot find input file {0}.'), - output: checkFile(c.output, 'Cannot find output file {0}.'), + input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : null, + output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : null, id: config.count, }); } @@ -246,8 +246,8 @@ export async function readYamlCases(folder: string, cfg: Dictionary = {}, a for (const c of subtask.cases) { config.count++; cases.push({ - input: checkFile(c.input, 'Cannot find input file {0}.'), - output: checkFile(c.output, 'Cannot find output file {0}.'), + input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : null, + output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : null, id: config.count, }); } @@ -260,7 +260,7 @@ export async function readYamlCases(folder: string, cfg: Dictionary = {}, a }); } } else { - const c = await readAutoCases(folder, { next }); + const c = await readAutoCases(folder, { next }, cfg); config.subtasks = c.subtasks; config.count = c.count; } diff --git a/packages/hydrojudge/src/judge/default.ts b/packages/hydrojudge/src/judge/default.ts index 5bae3b823..c2451bb90 100644 --- a/packages/hydrojudge/src/judge/default.ts +++ b/packages/hydrojudge/src/judge/default.ts @@ -36,7 +36,7 @@ function judgeCase(c, sid) { } const { filename } = ctx.config; const copyIn = { ...ctx.execute.copyIn }; - if (filename) copyIn[`${filename}.in`] = { src: c.input }; + if (filename) copyIn[`${filename}.in`] = c.input ? { src: c.input } : { content: '' }; const copyOut = filename ? [`${filename}.out`] : []; const stdin = filename ? null : c.input; const stdout = path.resolve(ctx.tmpdir, `${c.id}.out`); diff --git a/packages/hydrojudge/src/judge/interactive.ts b/packages/hydrojudge/src/judge/interactive.ts index 3cf3a7499..60f043f9b 100644 --- a/packages/hydrojudge/src/judge/interactive.ts +++ b/packages/hydrojudge/src/judge/interactive.ts @@ -17,8 +17,8 @@ const Score = { function judgeCase(c) { return async (ctx, ctxSubtask) => { - ctx.executeInteractor.copyIn.in = { src: c.input }; - ctx.executeInteractor.copyIn.out = { src: c.output }; + ctx.executeInteractor.copyIn.in = c.input ? { src: c.input } : { content: '' }; + ctx.executeInteractor.copyIn.out = c.output ? { src: c.output } : { content: '' }; ctx.executeInteractor.copyIn['testlib.h'] = { src: resolve(__dirname, '../../files/testlib.h') }; const [{ code, time_usage_ms, memory_usage_kb }, resInteractor] = await run([ {