QOJ.ac

QOJ

Limite de temps : 5.0 s Limite de mémoire : 1024 MB Points totaux : 100 Difficulté: [afficher]
Statistiques

Little Cyan Fish 正在与 Prof. Kubic 进行一项社会实验。在这个实验中,有 $n$ 个人最初位于位置 $a_1, a_2, \dots, a_n$。你需要执行恰好 $n$ 次操作,且每个人只能被选中一次。在 $n$ 次操作的每一次中,你必须选择一个人,而所有其他人都会向这个被选中的人移动一步。

具体来说,如果你选择了第 $i$ 个人,那么对于每个第 $j$ 个人($j \neq i$):

  • 如果 $a_i > a_j$,则 $a_j \leftarrow a_j + 1$。
  • 如果 $a_i < a_j$,则 $a_j \leftarrow a_j - 1$。
  • 如果 $a_i = a_j$,则 $a_j$ 保持不变。

我们将数组 $a = (a_1, a_2, \dots, a_n)$ 的值定义为所有操作完成后,距离最远的两名成员之间的最小可能距离。

现在给定 $n$ 和 $n$ 个集合 $S_1, S_2, \dots, S_n$。数组 $a = (a_1, a_2, \dots, a_n)$ 是合法的,当且仅当:

  1. 对于所有 $1 \le i < n$,满足 $a_i \le a_{i+1}$。
  2. 对于所有 $1 \le i \le n$,满足 $a_i \in S_i$。

你需要求出所有合法数组 $a$ 的值之和。答案对 $998\,244\,353$ 取模。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 400$)。

接下来的 $n$ 行描述每个集合 $S_i$。每行的第一个整数是 $|S_i|$ ($0 \le |S_i| \le 800 + 1$)。随后是 $|S_i|$ 个范围在 $[0, 800]$ 内的互不相同的整数,表示该集合。

输出格式

输出一行,包含一个整数,表示答案。

样例

样例输入 1

5
3 1 2 3
1 2
0
4 0 2 3 4
2 2 3

样例输出 1

0

样例输入 2

5
4 1 2 3 7
4 5 7 8 9
4 2 3 6 9
5 0 1 4 7 9
8 0 1 2 3 6 7 8 9

样例输出 2

16

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.