QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#490258 | #5070. Check Pattern is Bad | pavement | WA | 14ms | 3628kb | C++17 | 2.6kb | 2024-07-25 13:47:39 | 2024-07-25 13:47:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
int T, n, m, dr[] = {-1, -1, -1, 0, 0, 1, 1, 1}, dc[] = {-1, 0, 1, -1, 1, -1, 0, 1};
char f[105][105];
bool bad, vis[105][105];
queue<ii> Q;
char chk(int r, int c) {
if (f[r][c] != '?') {
return 0;
}
if (r > 1 && c > 1) {
if (f[r - 1][c] != '?' && f[r][c - 1] != '?' && f[r - 1][c - 1] != '?' && f[r - 1][c] == f[r][c - 1] && f[r][c - 1] != f[r - 1][c - 1]) {
return f[r - 1][c];
}
}
if (r > 1 && c < m) {
if (f[r - 1][c] != '?' && f[r][c + 1] != '?' && f[r - 1][c + 1] != '?' && f[r - 1][c] == f[r][c + 1] && f[r - 1][c] != f[r - 1][c + 1]) {
return f[r - 1][c];
}
}
if (r < n && c > 1) {
if (f[r + 1][c] != '?' && f[r][c - 1] != '?' && f[r + 1][c - 1] != '?' && f[r][c - 1] == f[r + 1][c] && f[r + 1][c - 1] != f[r][c - 1]) {
return f[r][c - 1];
}
}
if (r < n && c < m) {
if (f[r + 1][c] != '?' && f[r][c + 1] != '?' && f[r + 1][c + 1] != '?' && f[r + 1][c] == f[r][c + 1] && f[r + 1][c + 1] != f[r + 1][c]) {
return f[r + 1][c];
}
}
return 0;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
bad = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> f[i][j];
vis[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (chk(i, j)) {
Q.emplace(i, j);
}
}
}
while (!Q.empty()) {
auto [r, c] = Q.front();
Q.pop();
if (vis[r][c]) {
continue;
}
vis[r][c] = 1;
f[r][c] = chk(r, c);
for (int k = 0; k < 8; k++) {
int nr = r + dr[k], nc = c + dc[k];
if (1 <= nr && nr <= n && 1 <= nc && nc <= m && chk(nr, nc)) {
Q.emplace(nr, nc);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (f[i][j] == '?') {
int cnt[2] = {};
for (int k : {0, 1, 3}) {
int ni = i + dr[k], nj = j + dc[k];
if (1 <= ni && ni <= n && 1 <= nj && nj <= m) {
cnt[f[ni][nj] == 'W']++;
}
}
if (cnt[0] < cnt[1]) {
f[i][j] = 'W';
} else {
f[i][j] = 'B';
}
}
}
}
for (int i = 2; i <= n; i++) {
for (int j = 2; j <= m; j++) {
if (f[i - 1][j - 1] != f[i - 1][j] && f[i - 1][j] == f[i][j - 1] && f[i - 1][j - 1] == f[i][j]) {
bad = 1;
}
}
}
if (bad) {
cout << "NO\n";
} else {
cout << "YES\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << f[i][j];
}
cout << '\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES BB BB NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 14ms
memory: 3628kb
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 WW WB BB WB BB YES BB BB BB BW WW WW NO NO YES B W W B B W W W B B YES BBWW WBWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW YES WBW WWW WWW WWW WWW WWW WWW WWW YES W B B B YES BBBB WBBB YES BBBBBB BBWBWB YES WWWWW YES BWWWWW WWBWWB BBBWWW WBWWWW YES B YES BWB BBB WBB WBB WWB WBB BBW BBB...
result:
wrong answer ans finds the answer, but out doesn't (test case 18)