#P2730. [IOI 1996 / USACO3.2] 魔板 Magic Squares
[IOI 1996 / USACO3.2] 魔板 Magic Squares
Description
This is a magic board with squares of equal size: | | | | | |:-:|:-:|:-:|:-:| | | | | |
For the board state shown above, we use the sequence to represent it. This is the initial state.
There are three basic operations, denoted by the uppercase letters , , and (you can change the board state using these operations). Below is a demonstration of applying them to the initial state:
: Swap the top and bottom rows. | | | | | |:-:|:-:|:-:|:-:| | | | | |
: Move the rightmost column to the leftmost position. | | | | | |:-:|:-:|:-:|:-:| | | | | |
: Rotate the four central cells clockwise. | | | | | |:-:|:-:|:-:|:-:| | | | | |
At any state during the transformation, all three basic operations can be applied.
Write a program to compute the shortest sequence of basic operations that transforms the initial state into the target state.
Input Format
A single line containing integers with , separated by spaces, representing the target state.
Output Format
The first line contains an integer, the length of the shortest operation sequence.
Starting from the second line, output the shortest sequence of operations as a string, wrapping every characters per line. If there are multiple solutions, output the lexicographically smallest one.
2 6 8 4 5 7 3 1
7
BCABCCB
Hint
Translation source: NOCOW.
Translated by ChatGPT 5
京公网安备 11011102002149号