No.283 Slide Puzzle and Magic Square
タグ : / 解いたユーザー数 16
作問者 :
紙ぺーぱー
Problem Statement
kamipeipaa likes sliding puzzles (reference), and he also likes magic squares (reference).
You are given the board of an $N × N$ sliding puzzle, so let's try to make a magic square.
On a board of $N × N$ cells, pieces with pairwise distinct integers from $1$ to $N^{2}-1$ written on them are arranged.
You may repeatedly slide a piece adjacent to the empty cell (above, below, left, or right of it) into the empty cell.
The puzzle is considered complete by putting the piece $N^{2}$ into the empty cell. The piece $N^2$ can be placed anywhere as long as the cell is empty.
Input
$N$
$A_{1,1}$ $A_{1,2}$ $…$ $A_{1,N}$
$A_{2,1}$ $A_{2,2}$ $…$ $A_{2,N}$
$⋮$
$A_{N,1}$ $A_{N,2}$ $…$ $A_{N,N}$
The first line contains an integer $1 \le N \le 50$ representing the size of the sliding puzzle.
$A_{i,j}$ are pairwise distinct integers from $0$ to $N^{2}-1$, where $0$ represents the empty cell.
Output
If a magic square can be made from the current board, print "possible" on the first line, and print the target magic square on the following $N$ lines.
The format of the magic square is the same as the input: print $N$ space-separated elements on each line.
If a magic square cannot be made, print "impossible".
This problem uses a special judge. You may print any magic square board that can be made from the current board.
Sample
Sample 1
Input
3 8 1 6 3 5 7 4 0 2
Output
possible 8 1 6 3 5 7 4 9 2
Putting 9 into the 0 gives a magic square.
Sample 2
Input
3 8 1 6 3 0 7 4 5 2
Output
possible 8 1 6 3 5 7 4 9 2
Sliding 5 into the position of the 0 and then putting in 9 gives a magic square.
Sample 3
Input
2 0 1 2 3
Output
impossible
If it is impossible, print only impossible.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。