Logo
(追記) (追記ここまで)

31150번 - Flood Fill 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB102292665.000%

문제

Given are two black and white $N \times M$ images $A$ and $B$.

The "flood fill" tool works as follows: you choose any cell $(x, y),ドル locate its connected component and flip the colors of all the cells in the component (if the cell was black, it becomes white, and if it was white, it becomes black). The connected component of the cell is the set of cells you can reach by going up/down/left/right without changing color.

You can apply the "flood fill" tool to image $A$ any number of times. What is the minimum number of cells in which $A$ can be different from $B$ after some sequence of operations?

입력

The first line of input contains two integers $N$ and $M$ (1ドル \le N, M \le 100$) --- the dimensions of the images.

Each of the next $N$ lines contains a binary string of length $M,ドル describing the corresponding row of the image $A$.

Each of the next $N$ lines contains a binary string of length $M,ドル describing the corresponding row of the image $B$.

Here 0 corresponds to the cell colored white, 1 corresponds to the cell colored black.

출력

Output a single integer --- the minimum possible number of cells in which $A$ can be different from $B$ after some sequence of operations.

제한

예제 입력 1

1 3
101
010

예제 출력 1

1

예제 입력 2

4 4
0001
0101
0101
0111
0000
1110
1110
1110

예제 출력 2

7

노트

In the first example, you can apply the tool to the middle cell twice. This way, two images will differ only in 1ドル$ cell.

In the second example, you can just make the entire image black. This way, two images will differ in 7ドル$ cells.

출처

Contest > Open Cup > 2021/2022 Season > Stage 7: Grand Prix of Southeastern Europe E번

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2021 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /