QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#896. 马

Statistics

Big Horse 是马之神。他有 $n$ 种不同的马。由于他的视力不太好,他无法区分同种类的马。

现在他想把 $m$ 匹马排成一队。但马儿们非常活跃,它们可能会随意改变位置。不过,Big Horse 注意到只有相邻的两匹马可以交换位置,且仅当这两种马是朋友时才能交换。由于马可以随时交换位置,Big Horse 认为两个队列等价,当且仅当其中一个可以通过有限次交换变为另一个。

现在 Big Horse 有一个马的队列 $a = (a_1, \dots, a_m)$。他想在队列左侧添加一些其他的马。然而,Big Horse 分不清左右。因此,他想添加一个队列 $b = (b_1, \dots, b_k)$,使得 $b$ 与 $a$ 可交换:换句话说,$b_1, \dots, b_k, a_1, \dots, a_m$ 与 $a_1, \dots, a_m, b_1, \dots, b_k$ 等价。然而,这样的 $b$ 的数量可能太多了。Big Horse 只关心“极小”的这类队列 $b$。具体来说,他感兴趣的是满足以下条件的 $b$:

  • $b$ 与 $a$ 可交换,
  • $b$ 不等价于 $c_1, \dots, c_{k'}, d_1, \dots, d_{k''}$,其中 $c$ 与 $a$ 可交换且 $d$ 与 $a$ 可交换,
  • $b$ 在所有与它等价的队列中字典序最小。

他发现最多有 $n$ 个极小队列。他请求你帮助他找到它们。

输入格式

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

接下来有 $n - 1$ 行。第 $i$ 行包含 $n - i$ 个整数。第 $i$ 行的第 $j$ 个整数如果为 $1$,表示种类 $i$ 的马可以与种类 $i + j$ 的马交换,否则为 $0$。

下一行包含一个整数 $m$ ($1 \le m \le 300\,000$)。

最后一行包含 $m$ 个整数 $a_1, \dots, a_m$:队列中马的种类 ($1 \le a_i \le n$)。

输出格式

输出极小队列,每行一个。由于队列可能太长,当极小队列为 $b$ 时,你只需要输出哈希值 $b_1 + b_2 \cdot (n + 1) + \dots + b_k \cdot (n + 1)^{(k-1)} \pmod{998\,244\,353}$。

你应该按字典序输出极小队列(在哈希之前进行排序)。

样例

样例输入 1

3
1 1
0
5
2 1 3 2 3

样例输出 1

1
14

说明

样例中的两个极小队列是 $(1)$ 和 $(2, 3)$。

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.