eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Intellectual Property

Intellectual Property

Erast Kopi is famous Sudoku puzzle designer. Resounding success of his puzzle compilations caused a number of imitations and plagiarisms. Prior to sending a lawsuit he decided to get more evidence. Sudoku puzzle is a table\textbf{9}×\textbf{9}, divided into \textbf{3}×\textbf{3} subtables of \textbf{3}×\textbf{3} cells each. Each cell may contain a digit from \textbf{1} to \textbf{9}. The task is to fill empty cells with digits in a way that each row, each column and each of the \textbf{9} subtables \textbf{3}×\textbf{3} contains each digit from \textbf{1} to \textbf{9 }exactly once. Kopi has a database of Sudoku puzzles and he wants to check if it contains similar puzzles. The puzzle \textbf{P} is similar to the puzzle \textbf{Q}, if it is possible to transform the puzzle \textbf{P} into the puzzle \textbf{Q} using a sequence of the following operations: \begin{itemize} \item choose two digits \textbf{x} and \textbf{y} and replace all digits \textbf{x} with \textbf{y} and vice versa; \item swap two triples of rows: \textbf{(1, 2, 3)}, \textbf{(4, 5, 6)}, \textbf{(7, 8, 9)}; \item swap two rows in one triple of rows; \item swap two triples of columns: \textbf{(1, 2, 3)}, \textbf{(4, 5, 6)}, \textbf{(7, 8, 9)}; \item swap two columns in one triple of columns; \item flip along top-left --- bottom-right axis. After this operation columns become rows and vice versa. \end{itemize} \includegraphics{https://static.e-olymp.com/content/aa/aab6a854d1a7e4d6f25ff2b4e7688f0372797d28.jpg} Help Kopi to find similar puzzles in his database. \InputFile The first line of the input contains single integer \textbf{n} --- the number of puzzles in the database (\textbf{1} ≤ \textbf{n} ≤ \textbf{20}). The rest of the input contains description of \textbf{n} puzzles: \textbf{P_1}, \textbf{P_2}, ..., \textbf{P_n}. Each puzzle is described by nine lines that contain nine characters each. Each character is either a digit from \textbf{1} to \textbf{9}, or a dot ('\textbf{.}') denoting an empty cell. An empty line separates consecutive puzzles in the database. There are no spaces in the input file. The puzzles are not guaranteed to be solvable. \OutputFile Check if the puzzle \textbf{P_1} is similar to puzzles \textbf{P_2}, \textbf{P_3}, ..., \textbf{P_n} (in this order), than check if the puzzle \textbf{P_2} is similar to puzzles \textbf{P_3}, \textbf{P_4}, ..., \textbf{P_n} (in this order) and so on. If the puzzle \textbf{P_i} is similar to the puzzle \textbf{P_j} (\textbf{1} ≤ \textbf{i} < \textbf{j} ≤ \textbf{n}) output "\textbf{Yes}", otherwise output "\textbf{No}". If the answer is positive, the next line should contain an integer \textbf{q_ij} --- the number of operations required to transform the puzzle \textbf{P_i}to the puzzle \textbf{P_j}. The number of operations is not required to be minimal, however it must not exceed \textbf{1000}. In the following \textbf{q_ij} lines write the operations that transform the puzzle \textbf{P_i} to the puzzle \textbf{P_j}, one per line. Operations are encoded in the following way: \begin{itemize} \item "\textbf{D x y}" for swapping digits \textbf{x} and \textbf{y}; \item "\textbf{R a b}" for swapping triples of rows \textbf{(3a-2, 3a-1, 3a)} and \textbf{(3b-2, 3b-1, 3b)}; \item "\textbf{r a b}" for swapping rows \textbf{a} and \textbf{b}, rows must belong to same triple of rows; \item "\textbf{C a b}" for swapping triples of columns \textbf{(3a-2, 3a-1, 3a)} and \textbf{(3b-2, 3b-1, 3b)}; \item "\textbf{c a b}" for swapping columns \textbf{a} and \textbf{b}, columns must belong to same triple of columns; \item "\textbf{F}" for flipping along top-left --- bottom-right axis. \end{itemize} The columns are numbered from left to right and the rows are numbered from top to bottom as they are given in the input file, starting from one.
Ліміт часу 2 секунди
Ліміт використання пам'яті 256 MiB
Вхідні дані #1
4
.....1...
1........
.2.....8.
.........
8....9...
.........
....7....
...2...1.
2...4....

....2....
...7.4...
8.......9
.8...2..1
..2......
.........
.........
..1.8....
.........

1........
.........
.........
.........
.........
.........
.........
.........
.........

.....1...
1........
.2.....8.
.........
8....9...
.........
....7....
...2...1.
2...4....
Вихідні дані #1
Yes
7
F
R 1 2
r 7 9
c 5 6
c 4 5
C 2 3
D 1 8
No
Yes
2
r 4 6
c 7 9
No
Yes
7
F
R 2 3
r 4 5
r 5 6
c 7 9
C 1 2
D 1 8
No
Джерело ACM ICPC 2013–2014, NEERC, Northern Subregional Contest, St Petersburg, October 26, 2013