题目描述
Problem Background
Translated from COCI 2023/2024 Contest #4 T1「Bingo」
Problem Description
It's time to play Bingo!
To play Bingo, you need a game host and a wheel containing 90 balls. The balls in the wheel are numbered from $1$ to $90$, with each number written on exactly one ball.
Before the game starts, the host distributes a $5 \times 5$ grid to each of the $n$ players. Each cell in the grid contains an integer between $1$ and $90$. The numbers on each grid are unique, and no two players have the same grid.
After all players receive their grids, the game begins.
The host starts drawing balls from the wheel. After drawing a ball numbered $x_i$, the host announces the number to all players and sets the ball aside. Players check their grids and mark off the number if it appears on their grid.
A player shouts Bingo! when they have marked off all five numbers in a row, column, the main diagonal, or the anti-diagonal. At this point, the game ends, and that player wins.
To make the game more interesting, the host introduces an additional rule. Before anyone is allowed to shout Bingo!, the host will draw $m$ balls. (Even if a player has marked off five consecutive numbers, they must wait until $m$ balls are drawn before shouting Bingo!)
However, as soon as the host draws the $m$-th ball, a commotion occurs! All players shout Bingo!.
The host is unsure whom to believe. To resolve this situation, he seeks your help. Calculate how many players can shout Bingo! after $m$ balls are drawn.
Input Format
The first line of input contains an integer $n$ ($1 \le n \le 50$), representing the number of players.
The next $n \times 6$ lines are structured as follows:
- The first line contains a string of no more than 20 characters, consisting only of lowercase English letters, representing the player's name. No two players have the same name.
- The next 5 lines each contain 5 integers between $1$ and $90$, describing the player's grid. Each grid has unique numbers.
The next line contains an integer $m$ ($1 \le m \le 90$), representing the number of balls the host will draw.
The final line contains $m$ integers within the range $1$ to $90$, representing the numbers on the balls drawn by the host. Each number appears at most once.
Output Format
The first line of output contains an integer $k$, representing the number of players who can shout Bingo!.
The next $k$ lines contain their names, in the order they appear in the input.
Sample Input and Output
Sample Input #1
3
babylasagna
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
nataliebalmix
10 20 30 40 50
11 21 31 41 51
12 22 32 42 52
13 23 33 43 53
14 24 34 44 54
lettri
89 88 87 86 10
85 84 83 11 82
81 80 12 79 78
77 13 76 75 74
14 73 72 71 70
6
10 11 12 13 14 15
Sample Output #1
3
babylasagna
nataliebalmix
lettri
Sample Input #2
1
honi
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
4
1 2 49 50
Sample Output #2
0
Sample Input #3
4
rim
15 23 14 26 34
12 11 13 16 17
90 67 45 24 18
85 82 77 66 22
62 71 32 35 7
tim
61 89 25 63 12
29 30 31 32 33
11 17 42 24 18
88 82 77 66 22
44 71 54 35 7
dagi
15 23 14 26 34
12 11 13 16 17
90 67 45 24 18
85 82 77 66 22
62 71 36 35 7
dim
15 23 14 26 34
12 11 13 16 17
90 67 45 24 18
85 82 77 66 22
42 51 32 33 7
7
15 11 66 7 42 30 61
Sample Output #3
1
tim
Notes
Sample Explanation 1
babylasagna achieves Bingo! on the first row.
nataliebalmix achieves Bingo! on the first column.
lettri achieves Bingo! on the anti-diagonal from the bottom left to the top right.
Sample Explanation 2
Only 4 balls are drawn, so no one can mark off 5 numbers.
Subtasks
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 12 | There is only one player, i.e., $n=1$ |
| 2 | 22 | At most one player shouts Bingo! |
| 3 | 16 | No additional constraints |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分