#abc327c. C - Number Place

C - Number Place

Score : 250250 points

问题描述

存在一个 9×99\times 9 的网格 AA,其中每个单元格包含一个介于 1199(包括两端)之间的整数。具体来说,位于第 ii 行(从上到下数)和第 jj 列(从左到右数)的单元格中包含数值 Ai,jA_{i,j}

如果 AA 满足以下所有条件,则输出 Yes。否则,输出 No

  • 对于 AA 的每一行,该行中的九个单元格恰好包含从 1199 的每个整数各一次。
  • 对于 AA 的每一列,该列中的九个单元格恰好包含从 1199 的每个整数各一次。
  • AA 的行从上到下分成三个组,每组包含三行;同样地,将列从左到右分成三个组,每组包含三列。以这种方式从 AA 得到的所有 3×33\times 3 网格中,都恰好包含从 1199 的每个整数各一次。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a 9×99\times 9 grid AA, where each cell contains an integer between 11 and 99, inclusive.
Specifically, the cell at the ii-th row from the top and jj-th column from the left contains Ai,jA_{i,j}.

If AA satisfies all of the following conditions, print Yes. Otherwise, print No.

  • For each row of AA, the nine cells in that row contain each integer from 11 to 99 exactly once.
  • For each column of AA, the nine cells in that column contain each integer from 11 to 99 exactly once.
  • Divide the rows of AA 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 3×33\times 3 grid obtained from AA in this way contains each integer from 11 to 99 exactly once.

Constraints

  • 1Ai,j91\leq A_{i,j}\leq 9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

A1,1A_{1,1} A1,2A_{1,2} \ldots A1,9A_{1,9}

A2,1A_{2,1} A2,2A_{2,2} \ldots A2,9A_{2,9}

\vdots

A9,1A_{9,1} A9,2A_{9,2} \ldots A9,9A_{9,9}

Output

If the grid AA 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 AA is shown below.

The grid AA 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 AA is shown below.

For example, if you look at the top left 3×33\times 3 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 AA 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