logo AlgoBeat OnlineJudge
登录 注册

#216516. [GKS 2013 #B] Sudoku Checker

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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

:::align{center} :::

Given a completed 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 to , once each.
  • Each column contains each number from to , once each.
  • Divide the matrix into non-overlapping sub-matrices. Each sub-matrix contains each number from to , 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, . test cases follow. Each test case starts with an integer . The next lines describe a completed Sudoku solution, with each line contains exactly integers. All input integers are positive and less than .

输出格式

For each test case, output one line containing "Case #x: y", where x is the case number (starting from ) 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.

样例

样例输入 1

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

样例输出 1

Case #1: Yes
Case #2: No
Case #3: No

数据范围与提示

Limits

.

Test set 1 - Visible

.

Test set 2 - Hidden

.