

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
行 列のマス目を考えます。上から 番目、左から 番目のマスを と表すことにします。 全てのマスはそれぞれ白か黒のどちらかの色に塗られています。
次のような経路が存在するとき、このマス目を"良い"状態と呼びます。
- 常に白いマスの上にいながら、 から、一つ 右か下 のマスに移動することを繰り返し、 へ移動する。
ここで、"良い"状態ならば や が必ず白いことに注意してください。
あなたの仕事は、以下の操作を繰り返し、マス目を"良い"状態にすることです。最小で何回操作を行う必要があるか求めてください。なお、有限回の操作で必ず"良い"状態に出来ることが証明可能です。
- つの整数 を選ぶ。 を満たす全ての について、 の色を変更する。つまり、白色ならば黒色にし、黒色ならば白色にする。
制約
入力
入力は以下の形式で標準入力から与えられる。
ここで、 は #
か .
であり、#
は が黒色、.
は白色であることを表す。
出力
最小の操作回数を出力せよ。
入力例 1Copy
3 3 .## .#. ##.
出力例 1Copy
1
、つまりマス のみ色を変更すれば良いです。
入力例 2Copy
2 2 #. .#
出力例 2Copy
2
入力例 3Copy
4 4 ..## #... ###. ###.
出力例 3Copy
0
操作が必要ない場合も存在します。
入力例 4Copy
5 5 .#.#. #.#.# .#.#. #.#.# .#.#.
出力例 4Copy
4
Score : points
Problem Statement
Consider a grid with rows and columns of squares. Let denote the square at the -th row from the top and the -th column from the left. Each square is painted black or white.
The grid is said to be good if and only if the following condition is satisfied:
- From , we can reach by moving one square right or down repeatedly, while always being on a white square.
Note that and must be white if the grid is good.
Your task is to make the grid good by repeating the operation below. Find the minimum number of operations needed to complete the task. It can be proved that you can always complete the task in a finite number of operations.
- Choose four integers . For each pair (), invert the color of - that is, from white to black and vice versa.
Constraints
Input
Input is given from Standard Input in the following format:
Here represents the color of - #
stands for black, and .
stands for white.
Output
Print the minimum number of operations needed.
Sample Input 1Copy
3 3 .## .#. ##.
Sample Output 1Copy
1
Do the operation with to change just the color of , and we are done.
Sample Input 2Copy
2 2 #. .#
Sample Output 2Copy
2
Sample Input 3Copy
4 4 ..## #... ###. ###.
Sample Output 3Copy
0
No operation may be needed.
Sample Input 4Copy
5 5 .#.#. #.#.# .#.#. #.#.# .#.#.
Sample Output 4Copy
4