아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Sudoku 1

시간 제한1초메모리 제한512 MB

요약
일부가 채워진 유효한 일반화 스도쿠 판(n은 최대 20)이 주어지고 완성해가 보장될 때, 규칙을 지키면서 빈칸을 최대한 많이 채운 판을 출력한다.
난이도

보통10점 중 7점

유형
백트래킹, 구현, 행렬, 재귀
정답자
아직 제출이 없습니다

문제

Fereydun, the legendary Persian hero whose prophecy was to overcome Zahhak, believes that he needs a powerful mind together with a powerful body. He has just learned a new brain teaser, called Sudoku, from a Japanese trader. 

Sudoku is played on a board that is a grid of n2×n2n^2 \times n^2 cells. The whole grid is also partitioned into n2n^2 sub-grids, each of size n×nn \times n. Each cell can be empty or contain an integer from 11 to n2n^2 (inclusive). A Sudoku board is valid if it meets the following conditions:

  1. All numbers in each row are distinct.
  2. All numbers in each column are distinct.
  3. All numbers in each sub-grid are distinct.

The following figure shows two valid Sudoku boards with no empty cells:

Fereydun has a valid board with some empty cells and has asked for your help. Your task is to fill as many empty cells as you can while keeping the board valid. It is guaranteed that there is at least one way to fill all the empty cells while keeping the board valid. 

This is an output-only problem, so no source code submission is required. There are 1010 test cases. For each test case, you are given an input file containing a table AA as the initial state of a Sudoku board, and your task is to submit an output file containing a table BB as the final state of that Sudoku board after filling some of its empty cells. All A\[i]\[j]A\[i]\[j] and B\[i]\[j]B\[i]\[j] values (for 1≤i,j≤n21 \leq i,j \leq n^2) are integers between 00 and n2n^2 (inclusive), where value 00 indicates an empty cell.

입력

The input is in the following format:

  • line 11: ;;n\\;\\;n
  • line 1+i1+i (for 1≤i≤n21 \leq i \leq n^2): ;;A\[i]\[1];;A\[i]\[2];…;A\[i]\[n2]\\;\\; A\[i]\[1] \\;\\; A\[i]\[2] \\;\ldots \\; A\[i]\[n^2]

출력

The output must be in the following format:

  • line ii (for 1≤i≤n21 \leq i \leq n^2): ;;B\[i]\[1];;B\[i]\[2];…;B\[i]\[n2]\\;\\; B\[i]\[1] \\;\\; B\[i]\[2] \\;\ldots \\; B\[i]\[n^2]

제한

  • 2≤n≤202 \leq n \leq 20,
  • 0≤A\[i]\[j]≤n20 \leq A\[i]\[j] \leq n^2,
  • The board AA is valid, and all of its empty cells can be filled while keeping it valid.

예제1

  1. 예제 1

    입력
    2
    0 2 0 0
    3 0 0 0
    0 0 4 0
    0 0 0 1
    
    예상 출력
    4 2 3 0
    3 1 2 4
    1 3 4 2
    2 4 0 1