Superdoku
Time limit2sMemory limit512 MB
Given the first k rows of an n by n grid, decide whether the remaining rows can be filled so each row and column holds 1 to n, and print one completion.
Problem
Alice and Bob are big fans of math. They enjoy games built on numbers, and whenever they see a puzzle like Sudoku, they cannot resist solving it. The goal of Sudoku is to fill a grid so that each row, each column, and each of the nine boxes contains the digits 1 to 9. The setter provides a partially filled grid, and a well-posed puzzle has exactly one solution.
Problem
Superdoku uses an grid. There are no box constraints. Instead, each row and each column must contain every integer from 1 to . To simplify the game, Alice and Bob fill in the first rows completely before play begins. Your task is to determine whether the grid can be completed.
Input
The first line contains two integers () and (), separated by a space. Each of the next lines contains integers, giving the first rows of the grid. Every integer is between 1 and , inclusive.
Output
If a solution exists, print yes on the first line, followed by lines with space-separated integers each, giving one valid grid. If no solution exists, print only no. If several solutions exist, print any one of them.