B - Roulette Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

1 、人 2\ldots 、人 NN 人の人がルーレットの賭けに参加しました。 このルーレットの出目は、0 から 36 までの 37 個の整数のうちいずれかです。 i = 1, 2, \ldots, N について、人 i37 個の目のうち C_i 個の目 A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i} に賭けました。

ルーレットが回され、出目は X でした。 X に賭けた人たちのうち、賭けた目の個数が最も少ない人たちの番号を昇順にすべて出力してください。

より形式的には、1 以上 N 以下の整数 i であって、下記の 2 つの条件をともに満たすものを昇順にすべて出力してください。

  • iX に賭けている。
  • 任意の j = 1, 2, \ldots, N について「人 jX に賭けているならば、C_i \leq C_j 」が成り立つ。

出力するべき番号が 1 つも無い場合もあることに注意してください(入力例2を参照)。

制約

  • 1 \leq N \leq 100
  • 1 \leq C_i \leq 37
  • 0 \leq A_{i, j} \leq 36
  • 任意の i = 1, 2, \ldots, N について、A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i} はすべて異なる。
  • 0 \leq X \leq 36
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
C_1
A_{1, 1} A_{1, 2} \ldots A_{1, C_1}
C_2
A_{2, 1} A_{2, 2} \ldots A_{2, C_2}
\vdots
C_N
A_{N, 1} A_{N, 2} \ldots A_{N, C_N}
X

出力

出力するべき番号を昇順にすベて並べた列を、B_1, B_2, \ldots, B_K とする。 下記の形式にしたがい、1 行目には出力するべき番号の個数 K を、 2 行目には B_1, B_2, \ldots, B_K を空白区切りで、それぞれ出力せよ。

K
B_1 B_2 \ldots B_K

入力例 1

4
3
7 19 20
4
4 19 24 0
2
26 10
3
19 31 24
19

出力例 1

2
1 4

ルーレットが回され、出目は 19 でした。 19 に賭けた人は人 1 、人 2 、人 43 人であり、それぞれが賭けた目の個数は 3, 4, 3 です。 よって、19 に賭けた人のうち、賭けた目の個数が最も少ない人は人 1 と人 42 人です。


入力例 2

3
1
1
1
2
1
3
0

出力例 2

0

ルーレットが回され出目は 0 でしたが、0 に賭けた人は一人もいないため、 出力するべき番号は 1 つもありません。

Score : 200 points

Problem Statement

N people, person 1, person 2, \ldots, person N, are playing roulette. The outcome of a spin is one of the 37 integers from 0 to 36. For each i = 1, 2, \ldots, N, person i has bet on C_i of the 37 possible outcomes: A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}.

The wheel has been spun, and the outcome is X. Print the numbers of all people who have bet on X with the fewest bets, in ascending order.

More formally, print all integers i between 1 and N, inclusive, that satisfy both of the following conditions, in ascending order:

  • Person i has bet on X.
  • For each j = 1, 2, \ldots, N, if person j has bet on X, then C_i \leq C_j.

Note that there may be no number to print (see Sample Input 2).

Constraints

  • 1 \leq N \leq 100
  • 1 \leq C_i \leq 37
  • 0 \leq A_{i, j} \leq 36
  • A_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i} are all different for each i = 1, 2, \ldots, N.
  • 0 \leq X \leq 36
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
C_1
A_{1, 1} A_{1, 2} \ldots A_{1, C_1}
C_2
A_{2, 1} A_{2, 2} \ldots A_{2, C_2}
\vdots
C_N
A_{N, 1} A_{N, 2} \ldots A_{N, C_N}
X

Output

Let B_1, B_2, \ldots, B_K be the sequence of numbers to be printed in ascending order. Using the following format, print the count of numbers to be printed, K, on the first line, and B_1, B_2, \ldots, B_K separated by spaces on the second line:

K
B_1 B_2 \ldots B_K

Sample Input 1

4
3
7 19 20
4
4 19 24 0
2
26 10
3
19 31 24
19

Sample Output 1

2
1 4

The wheel has been spun, and the outcome is 19. The people who has bet on 19 are person 1, person 2, and person 4, and the number of their bets are 3, 4, and 3, respectively. Therefore, among the people who has bet on 19, the ones with the fewest bets are person 1 and person 4.


Sample Input 2

3
1
1
1
2
1
3
0

Sample Output 2

0

The wheel has been spun and the outcome is 0, but no one has bet on 0, so there is no number to print.