#abc314b. B - Roulette

B - Roulette

Score : 200200 points

问题描述

NN 名玩家(编号为 1122\ldotsNN)正在玩轮盘赌。每次旋转的结果是 3737 个整数之一,从 003636。对于每个 i=1,2,,Ni = 1, 2, \ldots, N,第 ii 名玩家在 3737 种可能的结果中押注了其中的 CiC_i 项:Ai,1A_{i, 1}Ai,2A_{i, 2}\ldotsAi,CiA_{i, C_i}

现在轮盘已经转动并产生了结果 XX。请按 升序 打印所有以最少押注数押中 XX 的玩家编号。

更正式地讲,请按照 升序 打印所有满足以下两个条件的 11NN 之间的整数 ii

  • 玩家 ii 押中了结果 XX
  • 对于每个 j=1,2,,Nj = 1, 2, \ldots, N,如果玩家 jj 也押中了结果 XX,则有 CiCjC_i \leq C_j

请注意,可能存在没有数字需要打印的情况(参见示例输入 2)。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

NN people, person 11, person 22, \ldots, person NN, are playing roulette. The outcome of a spin is one of the 3737 integers from 00 to 3636. For each i=1,2,,Ni = 1, 2, \ldots, N, person ii has bet on CiC_i of the 3737 possible outcomes: Ai,1,Ai,2,,Ai,CiA_{i, 1}, A_{i, 2}, \ldots, A_{i, C_i}.

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

More formally, print all integers ii between 11 and NN, inclusive, that satisfy both of the following conditions, in ascending order:

  • Person ii has bet on XX.
  • For each j=1,2,,Nj = 1, 2, \ldots, N, if person jj has bet on XX, then CiCjC_i \leq C_j.

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

Constraints

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

Input

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

NN

C1C_1

A1,1A_{1, 1} A1,2A_{1, 2} \ldots A1,C1A_{1, C_1}

C2C_2

A2,1A_{2, 1} A2,2A_{2, 2} \ldots A2,C2A_{2, C_2}

\vdots

CNC_N

AN,1A_{N, 1} AN,2A_{N, 2} \ldots AN,CNA_{N, C_N}

XX

Output

Let B1,B2,,BKB_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, KK, on the first line, and B1,B2,,BKB_1, B_2, \ldots, B_K separated by spaces on the second line:

KK

B1B_1 B2B_2 \ldots BKB_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 1919. The people who has bet on 1919 are person 11, person 22, and person 44, and the number of their bets are 33, 44, and 33, respectively. Therefore, among the people who has bet on 1919, the ones with the fewest bets are person 11 and person 44.

Sample Input 2

3
1
1
1
2
1
3
0

Sample Output 2

0

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

update @ 2024/3/10 08:57:39