Skip to content

Commit 2bd4bd5

Browse files
committed
feat(luogu): use TagInfo[] for tags
1 parent 6eaa6ff commit 2bd4bd5

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

src/platforms/luogu.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import type { Contest as BaseContest } from '../contest';
77
import type { PlatformOptions } from '../platform';
8-
import type { Problem as BaseProblem, ProblemDescriptionObject } from '../problem';
8+
import type { Problem as BaseProblem, ProblemDescriptionObject, TagInfo } from '../problem';
99
import { FetchError } from 'ofetch';
1010
import { NotFoundError, Platform } from '../platform';
1111
import { addHeaders, UnOJError } from '../utils';
@@ -34,7 +34,7 @@ export type Problem = BaseProblem<
3434
ProblemDescriptionObject,
3535
number[],
3636
Difficulty,
37-
number[],
37+
TagInfo[],
3838
ProblemType
3939
>;
4040

@@ -120,11 +120,11 @@ export default class Luogu extends Platform<string> {
120120
link: new URL(path, this.baseURL).href,
121121

122122
description: {
123-
background: content.background,
124-
details: content.description,
125-
input: content.formatI,
126-
output: content.formatO,
127-
hint: content.hint,
123+
background: content.background || '',
124+
details: content.description || '',
125+
input: content.formatI || '',
126+
output: content.formatO || '',
127+
hint: content.hint || '',
128128
},
129129

130130
samples: (data.problem.samples as Array<[string, string]>).map(([a, b]) => ({
@@ -135,7 +135,7 @@ export default class Luogu extends Platform<string> {
135135
timeLimit: data.problem.limits.time,
136136
memoryLimit: (data.problem.limits.memory as number[]).map(v => v * 1024),
137137
difficulty: data.problem.difficulty as Difficulty,
138-
tags,
138+
tags: tags.map(t => ({ id: t })),
139139
};
140140
}
141141

src/problem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export interface ProblemDescriptionObject {
1717
/** A tag for a {@link Problem}. */
1818
export interface TagInfo<Id extends string | number = string | number> {
1919
id: Id
20-
name: string
20+
name?: string
2121
}
2222

2323
/** General problem information. */
2424
export interface Problem<
2525
Desc extends string | ProblemDescriptionObject = string | ProblemDescriptionObject,
2626
Limits extends number | number[] | undefined = number | number[] | undefined,
2727
Difficulty extends string | number | undefined = string | number | undefined,
28-
Tags extends TagInfo[] = TagInfo[],
28+
Tags extends string[] | TagInfo[] | undefined = string[] | TagInfo[] | undefined,
2929
Type extends string = string,
3030
> {
3131
id: string

tests/platforms/__snapshots__/luogu.spec.ts.snap

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ exports[`Luogu platform (problem) should work 1`] = `
3535
},
3636
],
3737
"tags": [
38-
1,
39-
353,
38+
{
39+
"id": 1,
40+
},
41+
{
42+
"id": 353,
43+
},
4044
],
4145
"timeLimit": [
4246
1000,
@@ -64,31 +68,21 @@ exports[`Luogu platform (problem) should work 2`] = `
6468
6569
a180285 能从景点 $i$ 滑到景点 $j$ 当且仅当存在一条 $i$$j$ 之间的边,且 $i$ 的高度**不小于** $j$。与其他滑雪爱好者不同,a180285 喜欢用最短的滑行路径去访问尽量多的景点。如果仅仅访问一条路径上的景点,他会觉得数量太少。
6670
67-
于是 a18028 5拿出了他随身携带的时间胶囊。这是一种很神奇的药物,吃下之后可以立即回到上个经过的景点(不用移动也不被认为是 a180285 滑行的距离)。
71+
于是 a180285 拿出了他随身携带的时间胶囊。这是一种很神奇的药物,吃下之后可以立即回到上个经过的景点(不用移动也不被认为是 a180285 滑行的距离)。
6872
69-
请注意,这种神奇的药物是可以连续食用的,即能够回到较长时间之前到过的景点(比如上上个经过的景点和上上上个经过的景点)。 现在,a180285站在 $1$ 号景点望着山下的目标,心潮澎湃。他十分想知道在不考虑时间胶囊消耗的情况下,以最短滑行距离滑到尽量多的景点的方案(即满足经过景点数最大的前提下使得滑行总距离最小)。你能帮他求出最短距离和景点数吗?
70-
"
73+
请注意,这种神奇的药物是可以连续食用的,即能够回到较长时间之前到过的景点(比如上上个经过的景点和上上上个经过的景点)。 现在,a180285 站在 $1$ 号景点望着山下的目标,心潮澎湃。他十分想知道在不考虑时间胶囊消耗的情况下,以最短滑行距离滑到尽量多的景点的方案(即满足经过景点数最大的前提下使得滑行总距离最小)。你能帮他求出最短距离和景点数吗?"
7174
,
7275
"hint":
73-
"【数据范围】
74-
对于 $ 30\\% $ 的数据,$ 1 \\le n \\le 2000 $
75-
对于 $ 100\\% $ 的数据,$ 1 \\le n \\le 10^5 $
76-
76+
"对于 $ 30\\% $ 的数据,$ 1 \\le n \\le 2000 $
7777
78-
对于所有的数据,保证 $ 1 \\le m \\le 10^6 $ , $ 1 \\le h_i \\le 10^9 $ ,$ 1 \\le k_i \\le 10^9 $。
79-
"
78+
对于 $ 100\\% $ 的数据,$ 1 \\le n \\le 10^5 , 1 \\le m \\le 10^6 , 1 \\le h_i \\le 10^9 , 1 \\le k_i \\le 10^9 $。"
8079
,
8180
"input":
82-
"输入的第一行是两个整数 $n,m$
83-
接下来一行有 $n$ 个整数 $h_i$,分别表示每个景点的高度。
81+
"输入的第一行是两个整数 $n,m$。接下来一行有 $n$ 个整数 $h_i$,分别表示每个景点的高度
8482
85-
接下来 $m$ 行,表示各个景点之间轨道分布的情况。每行三个整数 $u,v,k$,表示编号为 $u$ 的景点和编号为 $v$ 的景点之间有一条长度为 $k$ 的轨道。
86-
"
87-
,
88-
"output":
89-
"输出一行,表示 a180285 最多能到达多少个景点,以及此时最短的滑行距离总和
90-
"
83+
接下来 $m$ 行,表示各个景点之间轨道分布的情况。每行三个整数 $u,v,k$,表示编号为 $u$ 的景点和编号为 $v$ 的景点之间有一条长度为 $k$ 的轨道。"
9184
,
85+
"output": "输出一行,表示 a180285 最多能到达多少个景点,以及此时最短的滑行距离总和。",
9286
},
9387
"difficulty": 5,
9488
"id": "P2573",
@@ -113,12 +107,24 @@ a180285 能从景点 $i$ 滑到景点 $j$ 当且仅当存在一条 $i$ 和 $j$
113107
},
114108
],
115109
"tags": [
116-
6,
117-
29,
118-
39,
119-
48,
120-
113,
121-
166,
110+
{
111+
"id": 6,
112+
},
113+
{
114+
"id": 29,
115+
},
116+
{
117+
"id": 39,
118+
},
119+
{
120+
"id": 48,
121+
},
122+
{
123+
"id": 113,
124+
},
125+
{
126+
"id": 166,
127+
},
122128
],
123129
"timeLimit": [
124130
5000,

0 commit comments

Comments
 (0)