QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272426 | #5070. Check Pattern is Bad | liangbowen | WA | 20ms | 3440kb | C++14 | 3.1kb | 2023-12-02 17:13:59 | 2023-12-02 17:14:00 |
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) //把必定能确定的点填掉
{
if (x <= 0 || x >= n || y <= 0 || y >= m) return {0, 0};
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;
void EMPTY() {while (!q.empty()) q.pop();}
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];
// if (n == 2 && m == 6) {
// for (int i = 1; i <= n; i++, cout << '\n') {
// for (int j = 1; j <= m; j++) {
// cout << a[i][j];
// }
// }
// cout << "===============================================\n";
// return;
// }
EMPTY();
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] = 'B', 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: 3432kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BB BB NO YES BWB WWW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 20ms
memory: 3440kb
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 BB BB BB BW WW BB NO NO YES B W B B B W W W B B YES BBWW WWWB WWWB BBWW BWWB BWWW WWWB BWWW BBBW BBBW YES WBW WBB BBB BBB WBW WBW BBB BWB YES W B B B YES BBBB WBBB YES BBBBBB BBWBWB YES WBWBB YES BWBBBB WWBBBB BBBWBB WBWWBW YES B YES BWB BBB WBB BBB WWB BBB BBW BBB...
result:
wrong answer (1, 1) should be B, you output W (test case 21)