Bingo
InterviewTime limit1sMemory limit1024 MB
Given bingo boards and a drawn sequence, list the players who have a full row, column, or diagonal marked after m draws, in input order.
- Level
Easy2 of 10
- Topics
- Array, Hash map, Simulation
- Solved
- No attempts yet
Problem
To play Bingo, you need a game master and a drum with balls, each containing a number from to , such that every number appears on exactly one ball. Before the game starts, the game master gives each of the players a board. Each field of a board contains an integer between and , and all integers on a board are distinct. Each player gets a unique board. After the boards are handed out, the game begins. The game master draws a ball with number , announces it, and sets the ball aside. Each player marks that number on their board if it appears there. A player who marks all numbers of a row, column, main diagonal, or antidiagonal shouts Bingo! and wins, which ends the game. In this version, the game master draws balls before anyone may shout Bingo!, even if a player already has a full line. When the -th ball is drawn, all players shout Bingo! at the same time. Find every player who has all the numbers marked in at least one row, column, or diagonal after the draws.
Input
The first line contains the integer (), the number of players. Then groups of six lines follow. The first line of each group is the player name, a string of at most lowercase English letters. No two players have the same name. The next five lines each contain five integers between and , describing the board. All integers on a board are distinct. The next line contains the integer (), the number of balls drawn. The next line contains integers between and , the drawn numbers in order. Each number is drawn at most once.
Output
On the first line, print , the number of players who have Bingo! after draws. Then print the names of those players, one per line, in the same order as they appear in the input.