Universal Cup Judging System

Universal Cup

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

検索アルゴリズムでは、次のような問題によく遭遇します。多数のエントリと 1 つのキーワード列があり、キーワードに一致するエントリを見つけたいとします。例えば、エントリ「2025 China Collegiate Programming Contest (CCPC) Jinan Regional Contest」はキーワード「2025 CCPC Jinan」に一致します。なお、キーワード列はエントリ内で連続して現れる必要はなく、エントリの部分列として現れれば十分です。

実用上の観点から、次のような関連度アルゴリズムを定義できます。各部分列が与えられたキーワード列と完全に一致するような、互いに重ならない(添字を共有しない)部分列をエントリからできるだけ多く選びます。このとき、選んだ部分列の個数を関連度とします。

この問題では、各単語は正の整数で表されます。長さ $m$ のキーワード列が与えられ、問題を簡単にするためキーワードはすべて相異なります。さらに $n$ 個のエントリが与えられ、$i$ 番目のエントリは長さ $l_i$ の正の整数列です。あなたの目標は、各エントリの関連度を計算することです。

入力

入力の 1 行目には、キーワード列の長さを表す整数 $m$($1 \le m \le 10$)が与えられます。

次の行には、キーワード列を表す $m$ 個の整数 $b_1, b_2, \dots, b_m$($1 \le b_i \le m$)が与えられます。$b_1, b_2, \dots, b_m$ はすべて相異なることが保証されます。

次の行には、エントリの個数を表す整数 $n$($1 \le n \le 100$)が与えられます。

続く $n$ 行のうち、$i$ 行目にはまず $i$ 番目のエントリの長さを表す整数 $l_i$($1 \le l_i \le 10^6$)が与えられます。続いて、$i$ 番目のエントリの内容を表す $l_i$ 個の整数 $a_{i,1}, a_{i,2}, \dots, a_{i,l_i}$($1 \le a_{i,j} \le 10^6$)が与えられます。

すべてのエントリの長さの総和は $10^6$ を超えないことが保証されます。

出力

$n$ 行出力してください。$i$ 行目には、$i$ 番目のエントリの関連度を表す整数を出力してください。

入出力例

入力

4
4 2 1 3
3
8 4 2 1 3 4 2 3 1
9 1 4 2 4 1 2 1 3 3
12 1 1 2 3 4 2 1 1 2 1 3 3

出力

1
2
1

注記

以下では、部分列を表すために添字列を用います。

  • 1 番目のエントリでは、部分列として $[1, 2, 3, 7]$ を選ぶことができ、このとき $[a_1, a_2, a_3, a_7] = [4, 2, 1, 3]$ となってキーワード列と完全に一致します。
  • 2 番目のエントリでは、部分列として $[2, 3, 5, 9]$ と $[4, 6, 7, 8]$ を選ぶことができます。位置が重なっているため、$[2, 3, 7, 9]$ と $[4, 6, 7, 9]$ を同時に選ぶことはできないことに注意してください。

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.