10595 - Su Doku   

Description

src : UVA 989

pdf : UVA989

 

In many newspapers we may nd some puzzles to solve, one of those is Su Doku. Given a grid 9*9
with some of entries lled, the objective is to ll in the grid so that every row, every column, and every
3*3 box contains the digits 1 through 9.

Input

Input contains several test cases separated by a blank line. Each of them contains an integer such that 1<=n<=3 and a grid n^2*n^2 with some of the entries lled with digits from 1 to 2 (an entrie not fi lled will have 0). In this case, the objective is to fi ll in the grid so that every row, every column, and
every n*n box contains the digits 1 through n^2 .

Output

A solution for the problem. If exists more than one, you should give the lower one assuming a lexico-
graphic order. If there is no solution, you should print `NO SOLUTION'. For lexicographic comparison
you should consider lines in fi rst place. Print a blank line between test cases.

Sample Input  Download

Sample Output  Download

Tags




Discuss