#P7724. Ancient Archive Puzzle
Ancient Archive Puzzle
Ancient Archive Puzzle
You are given a 2×2 grid where each cell either contains a positive integer or is empty. In the grid, the positive integers present are exactly the first k positive integers (if any), and the remaining cells are empty. You are allowed to perform a series of moves to transform the grid.
In each move, you may choose a cell that contains a positive integer and an adjacent cell (sharing an edge) that is empty, and then move the integer into the empty cell.
You are provided with an initial configuration and a target configuration. Determine whether it is possible to transform the initial configuration into the target configuration by a finite sequence of valid moves.
Note:
- The grid size is fixed at 2×2.
- An integer
0
represents an empty cell. - The grid may contain no positive integers or may have no empty cell.
All formulas are represented in LaTeX format. For example, the grid size is given as $2\times2$, and the set of positive integers is $\{1,2,\dots, k\}$.
inputFormat
The input consists of two 2×2 grids. The first grid is the initial configuration, and the second grid is the target configuration. Each grid is described by 2 lines, and each line contains 2 integers separated by spaces. A value of 0
indicates an empty cell while any positive integer represents a tile.
For example:
1 0 0 2 0 1 0 2
outputFormat
Output YES
if it is possible to transform the initial configuration into the target configuration through a sequence of valid moves. Otherwise, output NO
.
sample
0 0
0 0
0 0
0 0
YES