問題一覧 > 通常問題

No.228 Yukiko-chan's 15 Puzzle

レベル : / AI推定難易度 : 625 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 248
作問者 : sugim48
お気に入りにしたユーザー ProblemId : 247 / 自分の提出
問題文最終更新日: 2026-06-25 11:39:28
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 111 (順位表) の他の問題:

Problem Statement

Yukiko-chan is playing a puzzle called the "15 puzzle".
The rules of the 15 puzzle are shown below.

Pieces with the numbers from 1 to 15 written on them are placed in order on a 4×4 board (see the figure below).
You repeatedly slide a piece adjacent to the empty square (above, below, left, or right of it) into the empty square.
You succeed if you can create the target arrangement of pieces.



Yukiko-chan has grown bored of the usual way of playing the 15 puzzle.
So she decided to play with the following new rule added.

Rule: A piece that has been slid once cannot be slid again

Given a target arrangement of pieces, determine whether that arrangement can be created.

Input

$a_{11}$ $a_{12}$ $a_{13}$ $a_{14}$
$a_{21}$ $a_{22}$ $a_{23}$ $a_{24}$
$a_{31}$ $a_{32}$ $a_{33}$ $a_{34}$
$a_{41}$ $a_{42}$ $a_{43}$ $a_{44}$

The target arrangement of pieces is given.
$a_{ij}$ are distinct integers from 0 to 15.
Here, 0 represents the empty square.
For example, the initial arrangement is input as in Sample 1.

Output

Print Yes if the target arrangement of pieces can be created, and No otherwise.
Print a newline at the end.

Sample

Sample 1
Input
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
Output
Yes

The initial arrangement is itself the target arrangement.

Sample 2
Input
1 2 3 4
5 6 7 8
9 10 12 0
13 14 11 15
Output
Yes

Sample 3
Input
1 2 3 4
5 6 7 8
9 10 12 15
13 14 11 0
Output
No

To create the target arrangement, the piece 15 would have to be slid at least 2 times.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。