mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: use case.score & normalizeSubtask API
This commit is contained in:
1 parent
310189bc4d
commit
539a1c44ce
14 files changed
+231
-201
No files matched your search
@@ -129,8 +129,8 @@ export interface FileInfo {
|
||||
export interface TestCaseConfig {
|
||||
input: string;
|
||||
output: string;
|
||||
time?: number;
|
||||
memory?: number;
|
||||
time?: string;
|
||||
memory?: string;
|
||||
score?: number;
|
||||
}
|
||||
|
||||
@@ -148,8 +148,8 @@ export enum SubtaskType {
|
||||
}
|
||||
|
||||
export interface SubtaskConfig {
|
||||
time?: number;
|
||||
memory?: number;
|
||||
time?: string;
|
||||
memory?: string;
|
||||
score?: number;
|
||||
if?: number[];
|
||||
id?: number;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { load } from 'js-yaml';
|
||||
import readYamlCases from '@hydrooj/utils/lib/cases';
|
||||
import type { ProblemConfig, ProblemConfigFile } from '../interface';
|
||||
import { normalizeSubtasks, parseMemoryMB, parseTimeMS } from '../utils';
|
||||
|
||||
export async function parseConfig(config: string | ProblemConfigFile = {}) {
|
||||
let cfg: ProblemConfigFile = {};
|
||||
if (typeof config === 'string') {
|
||||
// TODO should validate here?
|
||||
cfg = await readYamlCases(load(config) as Record<string, any>);
|
||||
} else if (typeof config === 'object') cfg = await readYamlCases(config);
|
||||
const cfg: ProblemConfigFile = typeof config === 'string'
|
||||
? await readYamlCases(load(config) as Record<string, any>)
|
||||
: await readYamlCases(config);
|
||||
const result: ProblemConfig = {
|
||||
count: 0,
|
||||
memoryMin: Number.MAX_SAFE_INTEGER,
|
||||
@@ -18,23 +17,19 @@ export async function parseConfig(config: string | ProblemConfigFile = {}) {
|
||||
};
|
||||
if (cfg.subType) result.subType = cfg.subType;
|
||||
if (cfg.target) result.target = cfg.target;
|
||||
if (cfg.subtasks.length) {
|
||||
for (const subtask of cfg.subtasks) {
|
||||
result.memoryMax = Math.max(result.memoryMax, subtask.memory);
|
||||
result.memoryMin = Math.min(result.memoryMin, subtask.memory);
|
||||
result.timeMax = Math.max(result.timeMax, subtask.time);
|
||||
result.timeMin = Math.min(result.timeMin, subtask.time);
|
||||
if (cfg.subtasks?.length) {
|
||||
for (const subtask of normalizeSubtasks(cfg.subtasks as any || [], (i) => i, cfg.time, cfg.memory)) {
|
||||
result.memoryMax = Math.max(result.memoryMax, ...subtask.cases.map((i) => parseMemoryMB(i.memory)));
|
||||
result.memoryMin = Math.min(result.memoryMin, ...subtask.cases.map((i) => parseMemoryMB(i.memory)));
|
||||
result.timeMax = Math.max(result.timeMax, ...subtask.cases.map((i) => parseTimeMS(i.time)));
|
||||
result.timeMin = Math.min(result.timeMin, ...subtask.cases.map((i) => parseTimeMS(i.time)));
|
||||
}
|
||||
} else if (cfg.time || cfg.memory) {
|
||||
} else {
|
||||
if (cfg.time) result.timeMax = result.timeMin = cfg.time as unknown as number;
|
||||
if (cfg.memory) result.memoryMax = result.memoryMin = cfg.memory as unknown as number;
|
||||
}
|
||||
if (result.memoryMax < result.memoryMin) {
|
||||
result.memoryMax = result.memoryMin = 256;
|
||||
}
|
||||
if (result.timeMax < result.timeMin) {
|
||||
result.timeMax = result.timeMin = 1000;
|
||||
}
|
||||
if (result.memoryMax < result.memoryMin) result.memoryMax = result.memoryMin = 256;
|
||||
if (result.timeMax < result.timeMin) result.timeMax = result.timeMin = 1000;
|
||||
if (cfg.langs) result.langs = cfg.langs;
|
||||
if (cfg.redirect) result.redirect = cfg.redirect.split('/', 2) as any;
|
||||
if (cfg.filename && result.type === 'default') {
|
||||
|
||||
Reference in new issue
Block a user