QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100 可 Hack ✓

#8020. 扫雷 II

统计

扫雷地图 $X$ 可以表示为一个 $n \times m$ 的网格。网格中的每个单元格要么是地雷,要么不是地雷。地雷单元格上没有数字。每个非地雷单元格都有一个数字,表示其周围地雷单元格的数量。(如果两个单元格至少共享一个公共点,则称一个单元格在另一个单元格周围。因此,不在边界上的每个单元格周围都有 8 个单元格。)下图是一个 $16 \times 30$ 的扫雷地图,其中标记的单元格表示地雷,空白单元格表示数字为 0 的非地雷单元格。

给定两个大小为 $n \times m$ 的扫雷地图 $A$ 和 $B$,你需要修改 $B$ 中至多 $\lfloor \frac{nm}{2} \rfloor$ 个单元格(将非地雷单元格改为地雷,或反之),使得 $A$ 中所有非地雷单元格上的数字之和与 $B$ 中所有非地雷单元格上的数字之和相等。(如果地图中没有非地雷单元格,则和视为 0。)

如果存在多种解,输出其中任意一个。如果不存在解,输出一行 "-1"。

输入格式

第一行包含两个整数 $n, m$ ($1 \le n, m \le 1000$),表示给定扫雷地图的大小。

接下来 $n$ 行,每行包含一个长度为 $m$ 的字符串,由 "." 和 "X" 组成,表示扫雷地图 $A$ 的第 $i$ 行。其中 "." 表示非地雷单元格,"X" 表示地雷单元格。

接下来 $n$ 行,每行包含一个长度为 $m$ 的字符串,由 "." 和 "X" 组成,表示扫雷地图 $B$ 的第 $i$ 行。其中 "." 表示非地雷单元格,"X" 表示地雷单元格。

输出格式

如果不存在解,输出一行 "-1"。

否则,输出 $n$ 行,表示修改后的扫雷地图 $B$。第 $i$ 行应包含一个长度为 $m$ 的字符串,由 "." 和 "X" 组成,表示修改后的地图 $B$ 的第 $i$ 行。其中 "." 表示非地雷单元格,"X" 表示地雷单元格。

请注意,你不需要输出非地雷单元格上的数字,因为这些数字可以根据输出的扫雷地图确定。

样例

输入 1

2 4
X..X
X.X.
X.X.
.X..

输出 1

X.XX
.X..

说明 1

我们修改了 $B$ 中的一个单元格。此时 $A$ 和 $B$ 中非地雷单元格上的数字之和均为 10。

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.