Mine Sweeper II
题号:NC214893
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
Special Judge, 64bit IO Format: %lld

题目描述

A mine-sweeper map can be expressed as an 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 8 cells around it.) The following is a 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 of size , you should modify at most (i.e. the largest nonnegative integer that is less than or equal to ) cells in (from a non-mine cell to a mine cell or vice versa) such that the sum of numbers in the non-mine cells in and the sum of numbers in the non-mine cells in are the same. (If a map has no non-mine cell, the sum is considered as 0.)

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

输入描述:

The first line contains two integers , denoting the size of given mine-sweeper maps.

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

The -th line of the following lines contains a length- string consisting of "." and "X" denoting the -th row of the mine-sweeper map . 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 lines denoting the modified mine-sweeper map . The -th line should contain a length- string consisting of "." and "X" denoting the -th row of the modified map . 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.
示例1

输入

复制
2 4
X..X
X.X.
X.X.
.X..

输出

复制
X.XX
.X..

说明

We modify one cell in {B}. Then the sums of the numbers on non-mine cells in {A} and {B} both equal 10.