#P9820. [ICPC 2020 Shanghai R] Mine Sweeper II

    ID: 9102 Type: RemoteJudge 1000ms 1024MiB Tried: 2 Accepted: 2 Difficulty: 4 Uploaded By: Tags>模拟其他数学2020上海Special JudgeO2优化ICPC

[ICPC 2020 Shanghai R] Mine Sweeper II

题目描述

A mine-sweeper map XX can be expressed as an n×mn\times m grid. Each cell of the grid is either a mine cell or a non-mine cell. A mine cell has no number on it. Each non-mine cell has a number representing the number of mine cells around it. (A cell is around another cell if they share at least one common point. Thus, every cell that is not on the boundary has 88 cells around it.) The following is a 16×3016\times 30 mine-sweeper map where a flagged cell denotes a mine cell and a blank cell denotes a non-mine cell with number 0.

Given two mine-sweeper maps A,BA, B of size n×mn\times m, you should modify at most nm2\left\lfloor\frac{nm}{2}\right\rfloor (i.e. the largest nonnegative integer that is less than or equal to nm2\frac{nm}{2}) cells in BB (from a non-mine cell to a mine cell or vice versa) such that the sum of numbers in the non-mine cells in AA and the sum of numbers in the non-mine cells in BB are the same. (If a map has no non-mine cell, the sum is considered as 00.)

If multiple solutions exist, print any of them. If no solution exists, print -1 in one line.

输入格式

The first line contains two integers n,m(1n,m1000)n, m\,(1\le n,m \le 1000), denoting the size of given mine-sweeper maps.

The ii-th line of the following nn lines contains a length-mm string consisting of . and X denoting the ii-th row of the mine-sweeper map AA. A . denotes for a non-mine cell and an X denotes for a mine cell.

The ii-th line of the following nn lines contains a length-mm string consisting of . and X denoting the ii-th row of the mine-sweeper map BB. A . denotes for a non-mine cell and an X denotes for a mine cell.

输出格式

If no solution exists, print -1 in one line.

Otherwise, print nn lines denoting the modified mine-sweeper map BB. The ii-th line should contain a length-mm string consisting of . and X denoting the ii-th row of the modified map BB. A . denotes for a non-mine cell and an X denotes for a mine cell.

Please notice that you need not print the numbers on non-mine cells since these numbers can be determined by the output mine-sweeper map.

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

提示

We modify one cell in BB. Then the sums of the numbers on non-mine cells in AA and BB both equal 1010.