Banner Home Page DIY Contests Problems Ranklist Status Statistics
pdf版的题目下载:初赛goo.gl/rfbDY,决赛goo.gl/fNcyY。K题请使用GUN C++提交,用VC/VC++提交会返回RE。

Endless Sudoku Problem

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 137   Accepted Submission(s) : 80

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the picture 1. In some of the cells are written decimal digits from 1 to 9. The other cells are empty. The goal is to fill the empty cells with decimal digits from 1 to 9, one digit per cell, in such way that in each row, in each column and in each marked 3x3 subsquare, all the digits from 1 to 9 to appear.A right sudoku is shown on the picture 2.
Today you don't need to solve the sudoku task.Give you a sudoku,your task is to write a program to judge whether it is a right sudoku.Noting that if it is a right sudoku,it must satisfy all the rules mention in the first paragraph.If it is a right sudoku,output "YES",otherwise,output "NO".

Input

The first line contains a singal integer n (n<=20) ,represent the number of the test cases.For each test case, 9 lines follow, corresponding to the rows of the table. On each line a string of exactly 9 decimal digits is given, corresponding to the cells in this line. It is guaruntee that the decimal digits in the cell is bettween 1-9.There will be a blank line between each case.

Output

If the give sudoku is a right sudoku,print "YES",else print "NO".

Sample Input

2
581493762
963712584
274865931
129546378
436187295
758329146
892671453
615934827
347258619

123456789
234567891
345678912
456789123
567891234
678912345
789123456
891234567
912345678

Sample Output

YES
NO

Author

beyondxgb

Source

2012年华南师范大学校赛初赛

Statistic | Submit | Back