QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#14097. 洪水填充

統計

给定两张大小为 $N \times M$ 的黑白图像 $A$ 和 $B$。

“油漆桶(flood fill)”工具的工作原理如下:你选择任意一个格子 $(x, y)$,找到它所在的连通块,并翻转该连通块中所有格子的颜色(如果格子原本是黑色,则变为白色;如果原本是白色,则变为黑色)。一个格子的连通块是指在不改变颜色的情况下,通过向上/下/左/右移动所能到达的格子集合。

你可以对图像 $A$ 使用任意次数的“油漆桶”工具。在进行某种操作序列后,图像 $A$ 与图像 $B$ 之间不同格子的最少数量是多少?

输入格式

第一行包含两个整数 $N$ 和 $M$($1 \le N, M \le 100$),表示图像的尺寸。

接下来的 $N$ 行,每行包含一个长度为 $M$ 的二进制字符串,描述图像 $A$ 的对应行。

再接下来的 $N$ 行,每行包含一个长度为 $M$ 的二进制字符串,描述图像 $B$ 的对应行。

这里 $0$ 对应白色格子,$1$ 对应黑色格子。

输出格式

输出一个整数,表示在进行某种操作序列后,图像 $A$ 与图像 $B$ 之间最少可能有多少个格子不同。

样例

输入 1

1 3
101
010

输出 1

1

输入 2

4 4
0001
0101
0101
0111
0000
1110
1110
1110

输出 2

7

说明

在第一个样例中,你可以对中间的格子使用两次工具。这样,两张图像将仅在 $1$ 个格子中不同。

在第二个样例中,你只需将整张图像都变成黑色。这样,两张图像将在 $7$ 个格子中不同。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.