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$ 與 $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.