| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 131 | 77 | 53 | 57.609% |
Farmer John has a square canvas represented by an $N$ by $N$ grid of cells (2ドル \leq N \leq 2000,ドル $N$ is even). He paints the canvas according to the following steps:
For example, suppose $N=8$ and FJ painted the following painting in the top-right quadrant in step 2:
.#.. .#.. .##. ....
Then after reflecting across the horizontal and vertical lines into the other quadrants in step 3, the canvas would look as follows:
..#..#.. ..#..#.. .##..##. ........ ........ .##..##. ..#..#.. ..#..#..
However, while FJ was sleeping, Bessie broke into his barn and stole his precious canvas. She totally vandalized the canvas—removing some painted cells and adding more painted cells! Before FJ woke up, she returned the canvas to FJ.
FJ would like to modify his canvas so that it once again satisfies the reflective condition: that is, it is the result of reflecting the top-right quadrant into each of the other quadrants. Since he only has a limited number of resources, he would like to achieve this in as few operations as possible, where a single operation consists of either painting a cell or removing paint from a cell.
You are given the canvas after Bessie's vandalism, as well as a sequence of $U$ (0ドル\le U \leq 10^5$) updates to the canvas, each toggling a single cell to '.' if it is '#', or vice versa. Before any updates, and after each update, output the minimum number of operations $x$ FJ needs to perform so that the reflective condition is satisfied.
The first line contains integers $N$ and $U$.
The next $N$ lines each contain $N$ characters representing the canvas after Bessie's vandalism. Every character is either '#' or '.'.
The following $U$ lines each contain integers $r$ and $c,ドル where 1ドル \leq r, c \leq N,ドル representing an update to the cell in the $r$th row from the top and $c$th column from the left of the canvas.
Output $U+1$ lines representing $x$ before any updates and after each update.
4 5 ..#. ##.# #### ..## 1 3 2 3 4 3 4 4 4 4
4 3 2 1 0 1
The following canvas satisfies the reflective condition and differs from the original canvas by 4 operations:
.... #### #### ....
It is impossible to make the original canvas satisfy the reflective condition using fewer than 4 operations.
After updating $(1, 3),ドル the canvas looks like this:
.... ##.# #### ..##
It now takes 3 operations to make the canvas satisfy the reflective condition.
After updating $(2, 3),ドル the canvas looks like this:
.... #### #### ..##
It now takes 2 operations to make the canvas satisfy the reflective condition.