QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272167 | #5070. Check Pattern is Bad | liangbowen | WA | 31ms | 3856kb | C++14 | 2.8kb | 2023-12-02 16:18:28 | 2023-12-02 16:18:29 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <queue>
#define mk make_pair
using namespace std;
int n, m; char a[105][105];
bool check(int x, int y)
{
if (a[x][y] == 'B' && a[x + 1][y] == 'W' && a[x][y + 1] == 'W' && a[x + 1][y + 1] == 'B') return false;
if (a[x][y] == 'W' && a[x + 1][y] == 'B' && a[x][y + 1] == 'B' && a[x + 1][y + 1] == 'W') return false;
return true;
}
pair <int, int> cover(int x, int y) //把必定能确定的点填掉
{
int yiw = 0, X = -1, Y = -1;
for (auto dx : {x, x + 1}) for (auto dy : {y, y + 1})
if (1 <= dx && dx <= n && 1 <= dy && dy <= m && a[dx][dy] == '?')
yiw++, X = dx, Y = dy;
if (yiw != 1) return (yiw == 0 && !check(x, y)) ? mk(-1, -1) : mk(0, 0);
bool black = false, white = false;
a[X][Y] = 'B'; if (check(x, y)) black = true;
a[X][Y] = 'W'; if (check(x, y)) white = true;
if (black && white) return a[X][Y] = '?', mk(0, 0);
else if (!black && !white) return mk(-1, -1);
else if (black) return a[X][Y] = 'B', mk(X, Y);
else if (white) return a[Y][Y] = 'W', mk(X, Y);
return mk(-1, -1);
}
queue <pair <int, int>> q;
bool cover_all()
{
while (!q.empty())
{
auto [x, y] = q.front(); q.pop();
for (auto dx : {x - 1, x, x + 1}) for (auto dy : {y - 1, y, y + 1})
if (1 <= dx && dx < n && 1 <= dy && dy < m)
{
auto [t1, t2] = cover(dx, dy);
if (t1 == -1 && t2 == -1) return false;
else if (t1 && t2) q.push({t1, t2});
}
}
return true;
}
bool end_check()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] == '?') return false;
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
if (!check(i, j)) return false;
return true;
}
inline int rnd(int l = 114514, int r = 1919810) {static int seed = 2333; seed = (((seed * 666666ll + 20050818) % 998244353) ^ 1000000007) % 1004535809; return seed % (r - l + 1) + l;}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
{
auto [t1, t2] = cover(i, j);
if (t1 == -1 && t2 == -1) return cout << "NO\n", void();
else if (t1 == 0 && t2 == 0) a[t1][t2] = '?';
else if (t1 && t2) q.push({t1, t2});
}
if (!cover_all()) return cout << "NO\n", void();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] == '?')
{
a[i][j] = (rnd() % 2 ? 'B' : 'W'), q.push({i, j});
if (!cover_all()) return cout << "NO\n", void();
}
if (!end_check()) return cout << "NO\n", void();
cout << "YES\n";
for (int i = 1; i <= n; i++, cout << '\n')
for (int j = 1; j <= m; j++) cout << a[i][j];
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T;
cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BB BW NO YES BWW WWW WWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 31ms
memory: 3856kb
input:
10000 9 2 BB BW WW WW ?W ?B B? W? BB 6 2 ?? ?B B? BW WW ?? 10 7 WBBBW?? ???BWWW ???BWWB ??WWBW? BBWBBWB WWB?WW? BWBW??? WWWWBBW BBWBB?W B?W?W?B 4 7 ??WBWWB ?BBWWWB ?W?BBB? BBBWBBB 10 1 B W ? B B W W W B ? 10 4 ??WW W?W? WWW? ???W ?W?? ?W?W W?W? ?W?W ???W ???W 8 3 WBW W?? ??? ??? W?W W?W ??? ?W? 4 1 ...
output:
YES BB BW WW WW BW BB BB WB BB YES WW WB BB BW WW BW NO NO YES B W B B B W W W B B YES WBWW WBWB WWWW WBWW WWWW WWWW WBWB WWWW WBBW BBBW YES WBW WWW BBB WWB WWW WWW WBB WWB YES W B B B YES BBWB WBWB YES BBBBBB BBWBWB YES WBWBW YES BWWWWW WWBWWB BBBWWB WWWWWW YES W YES BWB BBB WBW WBB WWB WBB BBW WBB...
result:
wrong answer (1, 1) should be B, you output W (test case 21)