#abc327c. C - Number Place
C - Number Place
Score : points
问题描述
存在一个 的网格 ,其中每个单元格包含一个介于 到 (包括两端)之间的整数。具体来说,位于第 行(从上到下数)和第 列(从左到右数)的单元格中包含数值 。
如果 满足以下所有条件,则输出 Yes
。否则,输出 No
。
- 对于 的每一行,该行中的九个单元格恰好包含从 到 的每个整数各一次。
- 对于 的每一列,该列中的九个单元格恰好包含从 到 的每个整数各一次。
- 将 的行从上到下分成三个组,每组包含三行;同样地,将列从左到右分成三个组,每组包含三列。以这种方式从 得到的所有 网格中,都恰好包含从 到 的每个整数各一次。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid , where each cell contains an integer between and , inclusive.
Specifically, the cell at the -th row from the top and -th column from the left contains .
If satisfies all of the following conditions, print Yes
. Otherwise, print No
.
- For each row of , the nine cells in that row contain each integer from to exactly once.
- For each column of , the nine cells in that column contain each integer from to exactly once.
- Divide the rows of into three groups, each of three rows, from top to bottom, and similarly divide the columns into three groups, each of three columns, from left to right. Each grid obtained from in this way contains each integer from to exactly once.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
If the grid satisfies all the conditions in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
2 3 4 5 6 7 8 9 1
5 6 7 8 9 1 2 3 4
8 9 1 2 3 4 5 6 7
3 4 5 6 7 8 9 1 2
6 7 8 9 1 2 3 4 5
9 1 2 3 4 5 6 7 8
Sample Output 1
Yes
The grid is shown below.
The grid satisfies all three conditions, so print Yes
.
Sample Input 2
1 2 3 4 5 6 7 8 9
2 3 4 5 6 7 8 9 1
3 4 5 6 7 8 9 1 2
4 5 6 7 8 9 1 2 3
5 6 7 8 9 1 2 3 4
6 7 8 9 1 2 3 4 5
7 8 9 1 2 3 4 5 6
8 9 1 2 3 4 5 6 7
9 1 2 3 4 5 6 7 8
Sample Output 2
No
The grid is shown below.
For example, if you look at the top left grid, you can see that the third condition is unsatisfied, so print No
.
Sample Input 3
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
1 2 3 4 5 6 7 8 9
4 5 6 7 8 9 1 2 3
7 8 9 1 2 3 4 5 6
Sample Output 3
No
The grid is shown below.
For example, if you look at the leftmost column, you can see that the second condition is unsatisfied, so print No
.
update @ 2024/3/10 01:50:54