問題一覧 > 通常問題

No.3558 Dominoes, Black and White

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 64
作問者 : 👑 みうね / テスター : fluorine TKTYI HoyHoyCharhang jastaway soryuusi0219 yaaya butsurizuki wasab1 tatesoto KumaTachiRen
お気に入りにしたユーザー ProblemId : 13259 / 自分の提出
問題文最終更新日: 2026-08-15 03:14:30
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
KCPC新歓杯2026 (順位表) の他の問題:

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.

SubtaskScoreConstraints
部分点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もしくは右上の雲マークをクリックしてアカウントを作成してください。