#C8077. One Move Sliding Puzzle
One Move Sliding Puzzle
One Move Sliding Puzzle
Given a 4x4 sliding puzzle represented as a sequence of 16 integers, where the number 0 represents the empty space, determine whether the puzzle can be solved to reach the goal state in exactly one sliding move. The goal state is defined as:
\( [1, 2, 3, 4,\ 5, 6, 7, 8,\ 9, 10, 11, 12,\ 13, 14, 15, 0] \)
A sliding move involves swapping the empty space with one of its adjacent (up, down, left, or right) tiles. Note that if the empty space is already at the bottom-right corner (position 16 in a 1-indexed view), it should be considered unsolvable in one move since the puzzle is already in the goal configuration and no move is performed.
inputFormat
The input is given from stdin as a single line containing 16 space-separated integers. These represent the current configuration of the puzzle in row-major order.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 15
outputFormat
The output, printed to stdout, should be a single line containing either YES
or NO
.
YES
indicates that the puzzle can be solved to the goal state in one sliding move, while NO
indicates that it cannot.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 15
YES