QOJ.ac

QOJ

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

#896. 馬

Statistics

Big Horse は馬の神様です。彼は $n$ 種類の異なる馬を飼っています。彼は目がそれほど良くないため、同じ種類の馬を区別することができません。

今、彼は $m$ 頭の馬を列に並べようとしています。しかし、馬は非常に活発で、勝手に位置を変えてしまうことがあります。Big Horse は、隣り合う2頭の馬だけが入れ替わることができ、かつその2種類の馬が「友達」である場合にのみ入れ替えが可能であることに気づきました。馬はいつでも位置を入れ替えることができるため、Big Horse は、有限回の入れ替えによって一方から他方へ到達できる場合、2つの列を等価であるとみなします。

今、Big Horse は馬の列 $a = (a_1, \dots, a_m)$ を持っています。彼はこの列の左側に他の馬をいくつか追加したいと考えています。しかし、Big Horse は左と右を区別できません。そのため、彼は $b$ が $a$ と可換であるような列 $b = (b_1, \dots, b_k)$ を追加したいと考えています。言い換えれば、$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$ が $a$ と可換であり、$d$ が $a$ と可換であるような $c_1, \dots, c_{k'}, d_1, \dots, d_{k''}$ と等価ではない。
  • $b$ は、それと等価なすべての列の中で辞書順最小である。

彼は、最小の列が最大でも $n$ 個存在することを見つけました。彼はあなたにそれらを見つける手助けを求めています。

入力

1行目には整数 $n$ ($1 \le n \le 200$) が与えられます。 続く $n-1$ 行には、$n-i$ 個の整数が与えられます。$i$ 行目の $j$ 番目の整数は、種類 $i$ の馬と種類 $i+j$ の馬が入れ替え可能であれば 1、そうでなければ 0 です。 次の行には整数 $m$ ($1 \le m \le 300\,000$) が与えられます。 最後の行には $m$ 個の整数 $a_1, \dots, a_m$ が与えられます。これは列に含まれる馬の種類を表します ($1 \le a_i \le n$)。

出力

最小の列を1行に1つずつ出力してください。列は非常に長くなる可能性があるため、最小の列が $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

注記

例における2つの最小の列は (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.