感觉像脑筋急转弯。
考虑所有数字之和就是相邻的 \((\text{雷}, \text{空地})\) 对数,因此翻转后这个对数不会改变。
然后由于抽屉原理,\(b \to a\) 和 \(b \to \operatorname{inv}(a)\) 中至少有一个操作次数 \(\le \left\lfloor\frac{nm}{2}\right\rfloor\),然后就做完了。
code
// Problem: B. Mine Sweeper II
// Contest: Codeforces - 2020 ICPC Shanghai Site
// URL: https://codeforces.com/gym/102900/problem/B
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 1010;
int n, m;
char a[maxn][maxn], b[maxn][maxn], c[maxn][maxn];
void solve() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%s", a[i] + 1);
for (int j = 1; j <= m; ++j) {
c[i][j] = (a[i][j] == 'X' ? '.' : 'X');
}
}
for (int i = 1; i <= n; ++i) {
scanf("%s", b[i] + 1);
}
int cnt = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cnt += (a[i][j] != b[i][j]);
}
}
if (cnt <= n * m / 2) {
for (int i = 1; i <= n; ++i) {
printf("%s\n", a[i] + 1);
}
} else {
for (int i = 1; i <= n; ++i) {
printf("%s\n", c[i] + 1);
}
}
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}