eolymp
bolt
Try our new interface for solving problems
Məsələlər

Rotation Game

Rotation Game

You have a board with height two and width \textbf{W}. The board is divided into \textbf{1}×\textbf{1} cells. Each row of the board is numbered \textbf{1} and \textbf{2} from top to bottom and each column is numbered \textbf{1} to \textbf{W} from left to right. We denote a cell at the \textbf{i}-th row in the \textbf{j}-th column by \textbf{(i, j)}. Initially, some checkers are placed on some cells of the board. Here we assume that each checker looks the same. So we do not distinguish each checker. You are allowed to perform the following operations on the board: Square rotation: Choose a \textbf{2}×\textbf{2} square on the board. Then move checkers in the \textbf{2}×\textbf{2} square such that the checkers rotate their position in the square by \textbf{90} degrees in either clockwise or counterclockwise direction. \includegraphics{https://static.e-olymp.com/content/9f/9f76353053152773c796120029d2c532a25863b5.jpg} Triangular rotation: Choose a set of cells on the board that form a triangle. Here, we call a set of cells triangle if it is formed by removing exactly one cell from a \textbf{2}×\textbf{2} square. In the similar manner with the square rotation, rotate checkers in the chosen triangle in either clockwise or counterclockwise direction. \includegraphics{https://static.e-olymp.com/content/50/50312b8fe4e6449824d00389c1a99a9b60c0a0d5.jpg} The objective in this problem is to transform the arrangement of the checkers into desired arrangement by performing a sequence of rotation operations. The information of the initial arrangement and the target arrangement are given as the input. For the desired arrangement, one of the following is specified for each cell \textbf{(i, j)}: i. cell \textbf{(i, j)} must contain a checker, ii. cell \textbf{(i, j)} must not contain a checker, or iii. there is no constraint for cell \textbf{(i, j)}. Compute the minimum required number of operations to move the checkers so the arrangement satisfies the constraints and output it. \InputFile The input is formatted as follows. \textbf{W} \textbf{s_11s_11…s_1W} \textbf{s_21s_21…s_2W} \textbf{t_11t_11…t_1W} \textbf{t_21t_21…t_2W} The first line of the input contains an integer \textbf{W} (\textbf{2} ≤ \textbf{W} ≤ \textbf{2000}), the width of the board. The following two lines contain the information of the initial arrangement. If a cell \textbf{(i, j)} contains a checker in the initial arrangement, \textbf{s_ij} is \textbf{o}. Otherwise, \textbf{s_ij} is \textbf{.}. Then an empty line follows. The following two lines contain the information of the desired arrangement. Similarly, if a cell \textbf{(i, j)} must contain a checker at last, \textbf{t_ij} is \textbf{o}. If a cell \textbf{(i, j)} must not contain a checker at last, \textbf{t_ij} is \textbf{.}. If there is no condition for a cell \textbf{(i, j)}, \textbf{t_ij} is \textbf{*}. You may assume that a solution always exists. \OutputFile Output the minimum required number of operations in one line.
Zaman məhdudiyyəti 3 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
3
.oo
o..

o.o
o..
Çıxış verilənləri #1
1
Mənbə Japan Alumni Group Summer Camp 2013 Day 4, 2013/09/23