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

Fix the Pond

Fix the Pond

A shrimp farm uses a rectangular pond built as a grid with \textbf{2N} rows and \textbf{2N+1} columns of square cells, for a given integer \textbf{N}. Each cell side is one meter long. The pond has exactly \textbf{(2N-1)}×\textbf{N} barriers of length two meters, used to temporarily isolate smaller sections inside the pond for breeding different kinds of shrimp. The barriers have their middle points fixed precisely at the integer coordinates \textbf{(a, b)}, for all \textbf{0} < a < \textbf{2N} and \textbf{0} < \textbf{b} < \textbf{2N+1}, where both \textbf{a} and \textbf{b }are odd, or both are even. Each barrier can be rotated around its middle point to change the pond configuration; however, by being rotated, a barrier switches between only two possible positions, always parallel to the pond sides, vertical or horizontal. The left part of the figure below shows a pond configuration, with \textbf{N = 3}. \includegraphics{https://static.e-olymp.com/content/72/72301ac059a488306f1846765ea2aa887d3545e8.jpg} At the end of every season the pond is closed for maintenance and cleaning. It must then be reconfigured so that a special machine can sweep the pond floor. The machine starts its work at the top left cell, and needs to pass through every cell exactly once, finishing in the bottom left cell. The right part of the figure shows one such reconfiguration, where six barriers were switched. For this example, though, four barrier switches would have been enough. You must write a program that given a pond configuration, determines the minimum number of barrier switches needed to reconfigure the pond as specified above. There is always at least one possible way to reconfigure the pond as specified. \InputFile Each test case is described using several lines. The first line contains an integer \textbf{N} indicating that the pond has \textbf{2N}rows and \textbf{2N+1} columns (\textbf{1} ≤ \textbf{N} ≤ \textbf{300}). Each of the next \textbf{2N-1} lines contains a string of \textbf{N} characters describing the orientation of the barriers. In the \textbf{i}-th line, the \textbf{j}-th character indicates the orientation of the barrier whose middle point is at coordinates \textbf{(i, 2j-1)} if i is odd, or \textbf{(i, 2j)} if \textbf{i} is even, for \textbf{i = 1, 2, ..., 2N-1} and \textbf{j = 1, 2, ..., N}. The character is the uppercase letter '\textbf{V}' if the orientation is vertical, or the uppercase letter '\textbf{H}' if it is horizontal. \OutputFile For each test case output a line with an integer representing the minimum number of barrier switches needed to reconfigure the pond as specified.
Лимит времени 2 секунды
Лимит использования памяти 64 MiB
Входные данные #1
3
HVH
VVV
HHH
HHH
VHV
1
H
1
V
Выходные данные #1
4
0
1
Источник ACM ICPC Regional Latino America 2012