#P16473. [GKS 2013 #B] Sudoku Checker

    ID: 16458 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>模拟2013Google Kick Start

[GKS 2013 #B] Sudoku Checker

题目描述

Sudoku is a popular single player game. The objective is to fill a 9×99 \times 9 matrix with digits so that each column, each row, and all 99 non-overlapping 3×33 \times 3 sub-matrices contain all of the digits from 11 through 99. Each 9×99 \times 9 matrix is partially completed at the start of game play and typically has a unique solution.

:::align{center} :::

Given a completed N2×N2{N^2} \times {N^2} Sudoku matrix, your task is to determine whether it is a valid solution. A valid solution must satisfy the following criteria:

  • Each row contains each number from 11 to N2{N^2}, once each.
  • Each column contains each number from 11 to N2{N^2}, once each.
  • Divide the N2×N2{N^2} \times {N^2} matrix into N2{N^2} non-overlapping N×N{N} \times {N} sub-matrices. Each sub-matrix contains each number from 11 to N2{N^2}, once each.

You don't need to worry about the uniqueness of the problem. Just check if the given matrix is a valid solution.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with an integer NN. The next N2N^2 lines describe a completed Sudoku solution, with each line contains exactly N2N^2 integers. All input integers are positive and less than 10001000.

输出格式

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 11) and y is "Yes" (quotes for clarity only) if it is a valid solution, or "No" (quotes for clarity only) if it is invalid. Note that the judge is case-sensitive, so answers of "yes" and "no" will not be accepted.

3
3
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 5 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
3
5 3 4 6 7 8 9 1 2
6 7 2 1 9 5 3 4 8
1 9 8 3 4 2 5 6 7
8 5 9 7 6 1 4 2 3
4 2 6 8 999 3 7 9 1
7 1 3 9 2 4 8 5 6
9 6 1 5 3 7 2 8 4
2 8 7 4 1 9 6 3 5
3 4 5 2 8 6 1 7 9
Case #1: Yes
Case #2: No
Case #3: No

提示

Limits

1T1001 \le T \le 100.

Test set 1 - Visible

N=3N = 3.

Test set 2 - Hidden

3N63 \le N \le 6.