#P10228. Bingo Game
Bingo Game
Bingo Game
It is time to play Bingo! In this game, there are \(n\) players, each receiving a unique \(5 \times 5\) board filled with distinct integers from \(1\) to \(90\). The numbers on each board are unique and all boards are different.
The host draws balls from a container containing 90 balls numbered from \(1\) to \(90\). After drawing a ball with number \(x_i\), the host announces the number and sets the ball aside. All players then mark the number on their board if it appears.
A player shouts Bingo! when any one of the following is completely marked (i.e. all 5 numbers are marked): any row, any column, the main diagonal (top-left to bottom-right), or the anti-diagonal (top-right to bottom-left). However, the host has introduced a twist: he will draw exactly \(m\) balls before any player is allowed to shout Bingo! Even if a board has a complete line earlier, they must wait until \(m\) balls are drawn.
At the moment the \(m^{th}\) ball is drawn, all players simultaneously check and shout Bingo! if they qualify. Your task is to determine how many players can shout Bingo! after \(m\) balls have been drawn.
inputFormat
The first line contains two integers \(n\) and \(m\) \((1 \le n \le 1000,\ 1 \le m \le 90)\) --- the number of players and the number of balls drawn.
The second line contains \(m\) distinct integers \(x_1, x_2, \ldots, x_m\) \((1 \le x_i \le 90)\) --- the numbers drawn by the host in order.
This is followed by \(n \times 5\) lines describing the boards of the players. For each player, there are 5 lines, each containing 5 distinct integers separated by spaces. All numbers on a board are in the range \(1\) to \(90\) and are all unique. Moreover, no two players have the same board.
outputFormat
Output a single integer --- the number of players who can shout Bingo! after the \(m\) balls have been drawn.
sample
1 13
1 2 3 4 5 10 20 30 40 50 60 70 80
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
1