(
subtasks: ParsedSubtask[], checkFile: (name: string, errMsg: string) => string,
time: number | string = '1000ms', memory: number | string = '256m', ignoreParseError = false,
timeRate = 1, memoryRate = 1,
)
| 142 | } |
| 143 | |
| 144 | export function normalizeSubtasks( |
| 145 | subtasks: ParsedSubtask[], checkFile: (name: string, errMsg: string) => string, |
| 146 | time: number | string = '1000ms', memory: number | string = '256m', ignoreParseError = false, |
| 147 | timeRate = 1, memoryRate = 1, |
| 148 | ): NormalizedSubtask[] { |
| 149 | subtasks.sort((a, b) => (a.id - b.id)); |
| 150 | const subtaskScore = getScore( |
| 151 | Math.max(100 - Math.sum(subtasks.map((i) => i.score || 0)), 0), |
| 152 | subtasks.filter((i) => !i.score).length, |
| 153 | ); |
| 154 | return subtasks.map((s, id) => { |
| 155 | s.cases.sort((a, b) => (a.id - b.id)); |
| 156 | const score = s.score || subtaskScore.next().value as number; |
| 157 | const caseScore = getScore( |
| 158 | Math.max(score - Math.sum(s.cases.map((i) => i.score || 0)), 0), |
| 159 | s.cases.filter((i) => !i.score).length, |
| 160 | ); |
| 161 | return { |
| 162 | id: id + 1, |
| 163 | type: 'min', |
| 164 | if: [], |
| 165 | ...s, |
| 166 | score, |
| 167 | time: parseTimeMS(s.time || time, !ignoreParseError) * timeRate, |
| 168 | memory: parseMemoryMB(s.memory || memory, !ignoreParseError) * memoryRate, |
| 169 | cases: s.cases.map((c, index) => ({ |
| 170 | id: index + 1, |
| 171 | ...c, |
| 172 | score: c.score || (s.type === 'sum' ? caseScore.next().value as number : score), |
| 173 | time: parseTimeMS(c.time || s.time || time, !ignoreParseError) * timeRate, |
| 174 | memory: parseMemoryMB(c.memory || s.memory || memory, !ignoreParseError) * memoryRate, |
| 175 | input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : '/dev/null', |
| 176 | output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : '/dev/null', |
| 177 | })) as NormalizedCase[], |
| 178 | }; |
| 179 | }); |
| 180 | } |
no test coverage detected