#abc355c. C - Bingo 2
C - Bingo 2
Score : points
问题陈述
有一个 的网格,其中从顶部第 行和从左侧第 列的单元格包含整数 。
在 轮中,会宣布整数。在第 轮,宣布整数 ,并且包含 的单元格被标记。确定首次实现 Bingo 的轮次。如果在 轮内没有实现 Bingo,则打印 -1
。
在这里,实现 Bingo 意味着满足以下条件之一:
- 存在一行,其中所有 个单元格都被标记。
- 存在一列,其中所有 个单元格都被标记。
- 存在一条对角线(从左上到右下或从右上到左下),其中所有 个单元格都被标记。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is an grid, where the cell at the -th row from the top and the -th column from the left contains the integer .
Over turns, integers will be announced. On Turn , the integer is announced, and the cell containing is marked. Determine the turn on which Bingo is achieved for the first time. If Bingo is not achieved within turns, print -1
.
Here, achieving Bingo means satisfying at least one of the following conditions:
- There exists a row in which all cells are marked.
- There exists a column in which all cells are marked.
- There exists a diagonal line (from top-left to bottom-right or from top-right to bottom-left) in which all cells are marked.
Constraints
- if .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If Bingo is achieved within turns, print the turn number on which Bingo is achieved for the first time; otherwise, print -1
.
Sample Input 1
3 5
5 1 8 9 7
Sample Output 1
4
The state of the grid changes as follows. Bingo is achieved for the first time on Turn .
Sample Input 2
3 5
4 2 9 7 5
Sample Output 2
-1
Bingo is not achieved within five turns, so print -1
.
Sample Input 3
4 12
13 9 6 5 2 7 16 14 8 3 10 11
Sample Output 3
9