No.3558 Dominoes, Black and White
タグ : / 解いたユーザー数 64
作問者 : 👑
jastaway
yaaya
butsurizuki
Problem Statement
There is a grid of cells with $N$ rows and $2N$ columns.
Each cell is painted white or black; overall, exactly $N^2$ cells are painted white and the remaining $N^2$ cells are painted black.
The color of the cell in the $i$-th row from the top ($1 \leq i \leq N$) and the $j$-th column from the left ($1 \leq j \leq 2N$) is represented by the character $S_{i,j}$. If $S_{i,j}$ is
., the cell is white; if it is #, the cell is black.
You may perform the following operation any number of times, $0$ or more.
- Choose $2$ cells that are adjacent by sharing an edge and have different colors, and swap their colors.
Your goal is to make all cells in the left half of the grid ($1 \leq j \leq N$) white and all cells in the right half ($N+1 \leq j \leq 2N$) black.
Find the minimum number of operations required to achieve the goal.
Input
The input is given from standard input in the following format.
$N$ $S_1$ $S_2$ $\vdots$ $S_N$
- $1 \leq N \leq 1000$
- $N$ is an integer
- $S_i$ is a string of length $2N$ consisting of
.and# - In the entire grid, there are exactly $N^2$ occurrences each of
.and#
Partial Score
This problem has partial scoring based on subtasks.
| Subtask | Score | Constraints |
|---|---|---|
| 部分点 | 10% (20 pts) | $N \leq 3$ |
| 満点 | 90% (180 pts) | 追加の制約はない |
Output
Print the minimum number of operations required to achieve the goal on $1$ line.
Sample
Sample 1
Input
1 #.
Output
1
The goal can be achieved with $1$ operation.
Sample 2
Input
2 ..## ..##
Output
0
The goal is already achieved from the start, so no operations are needed.
Sample 3
Input
3 .#.### #.#... ##..#.
Output
17
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。