mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: objective: new syntax support
This commit is contained in:
1 parent
b606ab2852
commit
44b2911f77
2 files changed
+27
-72
No files matched your search
@@ -32,83 +32,38 @@ export async function judge({
|
|||||||
let totalStatus = 0;
|
let totalStatus = 0;
|
||||||
if (!Object.keys(answers).length) throw new FormatError('Invalid standard answer.');
|
if (!Object.keys(answers).length) throw new FormatError('Invalid standard answer.');
|
||||||
for (const key in config.answers) {
|
for (const key in config.answers) {
|
||||||
|
const ansInfo = config.answers[key] as [string | string[], number] | Record<string, number>;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
||||||
|
const report = (status: STATUS, score: number, message: string) => {
|
||||||
const [subtaskId, caseId] = key.split('-').map(Number);
|
const [subtaskId, caseId] = key.split('-').map(Number);
|
||||||
const ansInfo = config.answers[key] as [string | string[], number];
|
totalScore += score;
|
||||||
const score = (+ansInfo[1]) || 0;
|
totalStatus = Math.max(totalStatus, status);
|
||||||
const baseInfo = {
|
next({
|
||||||
|
status: totalStatus,
|
||||||
|
case: {
|
||||||
subtaskId,
|
subtaskId,
|
||||||
id: caseId,
|
id: caseId,
|
||||||
time: 0,
|
time: 0,
|
||||||
memory: 0,
|
memory: 0,
|
||||||
|
status,
|
||||||
|
score,
|
||||||
|
message,
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
if (typeof answers[key] === 'string') {
|
const usrAns = answers[key].toString();
|
||||||
const stdAns = typeof ansInfo[0] === 'string' ? [ansInfo[0]] : ansInfo[0];
|
if (ansInfo instanceof Array) {
|
||||||
if (stdAns.some((ans) => ans.trim() === (answers[key] as any)?.trim())) {
|
const fullScore = (+ansInfo[1]) || 0;
|
||||||
totalScore += score;
|
const stdAns = ansInfo[0];
|
||||||
totalStatus = Math.max(totalStatus, STATUS.STATUS_ACCEPTED);
|
if (stdAns instanceof Array) {
|
||||||
next({
|
const ans = new Set(answers[key] instanceof Array ? answers[key] : [answers[key]]);
|
||||||
status: totalStatus,
|
if (stdAns.length === ans.size && Set.isSuperset(ans, stdAns)) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct');
|
||||||
case: {
|
else if (ans.size && Set.isSuperset(ans, stdAns)) report(STATUS.STATUS_WRONG_ANSWER, Math.floor(fullScore / 2), 'Partially Correct');
|
||||||
...baseInfo,
|
else report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect');
|
||||||
status: STATUS.STATUS_ACCEPTED,
|
} else if (stdAns.toString() === usrAns.trim()) report(STATUS.STATUS_ACCEPTED, fullScore, 'Correct ');
|
||||||
score,
|
else report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect');
|
||||||
message: 'Correct',
|
} else if (!ansInfo[usrAns]) report(STATUS.STATUS_WRONG_ANSWER, 0, 'Incorrect');
|
||||||
},
|
else report(STATUS.STATUS_ACCEPTED, +ansInfo[usrAns] || 0, 'Correct');
|
||||||
});
|
|
||||||
} else {
|
|
||||||
totalStatus = STATUS.STATUS_WRONG_ANSWER;
|
|
||||||
next({
|
|
||||||
status: totalStatus,
|
|
||||||
case: {
|
|
||||||
...baseInfo,
|
|
||||||
status: STATUS.STATUS_WRONG_ANSWER,
|
|
||||||
score: 0,
|
|
||||||
message: 'Incorrect',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const stdAns = new Set(ansInfo[0] || []);
|
|
||||||
const ans = new Set(answers[key] || []);
|
|
||||||
const correct = stdAns.size === ans.size && [...stdAns].every((x) => ans.has(x));
|
|
||||||
const partialCorrect = [...stdAns].some((x) => ans.has(x)) && [...ans].every((x) => stdAns.has(x));
|
|
||||||
if (correct) {
|
|
||||||
totalScore += score;
|
|
||||||
totalStatus = Math.max(totalStatus, STATUS.STATUS_ACCEPTED);
|
|
||||||
next({
|
|
||||||
status: totalStatus,
|
|
||||||
case: {
|
|
||||||
...baseInfo,
|
|
||||||
status: STATUS.STATUS_ACCEPTED,
|
|
||||||
score,
|
|
||||||
message: 'Correct',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else if (partialCorrect) {
|
|
||||||
totalScore += Math.floor(score / 2);
|
|
||||||
totalStatus = STATUS.STATUS_WRONG_ANSWER;
|
|
||||||
next({
|
|
||||||
status: totalStatus,
|
|
||||||
case: {
|
|
||||||
...baseInfo,
|
|
||||||
status: STATUS.STATUS_WRONG_ANSWER,
|
|
||||||
score: Math.floor(score / 2),
|
|
||||||
message: 'Partially Correct',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
totalStatus = STATUS.STATUS_WRONG_ANSWER;
|
|
||||||
next({
|
|
||||||
status: totalStatus,
|
|
||||||
case: {
|
|
||||||
...baseInfo,
|
|
||||||
status: STATUS.STATUS_WRONG_ANSWER,
|
|
||||||
score: 0,
|
|
||||||
message: 'Incorrect',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end({
|
end({
|
||||||
status: totalStatus, score: totalScore, time: 0, memory: 0,
|
status: totalStatus, score: totalScore, time: 0, memory: 0,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ declare global {
|
|||||||
sum: (...args: Array<number[] | number>) => number;
|
sum: (...args: Array<number[] | number>) => number;
|
||||||
}
|
}
|
||||||
interface SetConstructor {
|
interface SetConstructor {
|
||||||
isSuperset: (set: Set<any>, subset: Set<any>) => boolean;
|
isSuperset: (set: Set<any>, subset: Set<any> | Array<any>) => boolean;
|
||||||
intersection: <T>(setA: Set<T> | Array<T>, setB: Set<T> | Array<T>) => Set<T>;
|
intersection: <T>(setA: Set<T> | Array<T>, setB: Set<T> | Array<T>) => Set<T>;
|
||||||
union: <T>(setA: Set<T> | Array<T>, setB: Set<T> | Array<T>) => Set<T>;
|
union: <T>(setA: Set<T> | Array<T>, setB: Set<T> | Array<T>) => Set<T>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user