103141: [Atcoder]ABC314 B - Roulette
Description
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.
Output
问题描述
$N$个人,编号分别为$1$,$2$,$\ldots$,$N$,正在玩轮盘赌。每次旋转的结果是$0$到$36$中的$37$个整数之一。对于每个人$i=1,2,\ldots,N$,他都押注了$C_i$种可能的结果:$A_{i, 1}$,$A_{i, 2}$,$\ldots$,$A_{i, C_i}$。
轮盘已经旋转,结果是$X$。按照升序打印押注$X$最少的人的编号。
更正式地说,按照升序打印所有满足以下两个条件的整数$i$,$1$到$N$:
- 编号为$i$的人押注了$X$。
- 对于每个人$j=1,2,\ldots,N$,如果编号为$j$的人押注了$X$,则$C_i \leq C_j$。
注意可能没有要打印的数字(见样例输入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$是按升序打印的数字序列。使用以下格式,在第一行打印要打印的数字数量$K$,在第二行使用空格将$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$和$4$的人,他们押注的数量分别是$3$、$4$和$3$。因此,在押注$19$的人中,押注最少的是编号为$1$和$4$的人。
样例输入2
3 1 1 1 2 1 3 0
样例输出2
0
轮盘已经旋转,结果是$0$,但是没有人押注$0$,所以没有数字要打印。