QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#490795 | #5070. Check Pattern is Bad | pavement | WA | 31ms | 3648kb | C++17 | 2.8kb | 2024-07-25 16:26:12 | 2024-07-25 16:26:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
int T, n, m;
char f[105][105];
set<int> s[105], s2[2][105];
vector<iii> rngs[2];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> f[i][j];
}
}
for (int i = 1; i <= n; i++) {
vector<iii> cur;
int prv = -1;
for (int j = 1; j <= m; j++) {
if (f[i][j] == '?') {
continue;
} else {
if (prv != -1 && f[i][prv] != f[i][j]) {
// [prv, j]
rngs[(i & 1) ^ (f[i][prv] == 'W')].eb(prv, j - 1, i);
} else if (prv == -1) {
for (int k = 1; k < j; k++) {
f[i][k] = f[i][j];
}
} else {
for (int k = prv + 1; k < j; k++) {
f[i][k] = f[i][j];
}
}
prv = j;
}
}
if (prv != -1) {
for (int k = prv + 1; k <= m; k++) {
f[i][k] = f[i][prv];
}
} else {
for (int k = 1; k <= m; k++) {
f[i][k] = 'W';
}
}
}
bool glob_bad = 0;
for (int b = 0; b < 2; b++) {
for (int i = 1; i <= n; i++) {
s[i].clear();
for (int j = 1; j <= m; j++) {
s[i].insert(j);
}
}
sort(rngs[b].begin(), rngs[b].end(), [](const auto &lhs, const auto &rhs) {
if (get<1>(lhs) == get<1>(rhs)) {
return get<0>(lhs) < get<0>(rhs);
} else {
return get<1>(lhs) < get<1>(rhs);
}
});
for (auto [l, r, idx] : rngs[b]) {
//~ cout << "@ " << b << ' ' << l << ' ' << r << ' ' << idx << '\n';
int ch = -1;
for (int i = l; i <= r; i++) {
bool bad = 0;
for (int delta : {-1, 1}) {
if (1 <= idx + delta && idx + delta <= n) {
if (s[idx + delta].find(i) == s[idx + delta].end()) {
bad = 1;
}
}
}
if (!bad) {
ch = i;
break;
}
}
if (ch == -1) {
glob_bad = 1;
} else {
s[idx].erase(ch);
s2[b][idx].insert(ch);
}
}
}
if (glob_bad) {
cout << "NO\n";
} else {
for (int b = 0; b < 2; b++) {
for (auto [l, r, idx] : rngs[b]) {
auto it = s2[b][idx].lower_bound(l);
assert(it != s2[b][idx].end() && *it <= r);
for (int i = l + 1; i <= *it; i++) {
f[idx][i] = "BW"[b ^ (idx & 1)];
}
for (int i = *it + 1; i <= r; i++) {
f[idx][i] = "WB"[b ^ (idx & 1)];
}
}
}
cout << "YES\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << f[i][j];
}
cout << '\n';
}
}
for (int b = 0; b < 2; b++) {
rngs[b].clear();
for (int i = 1; i <= n; i++) {
s[i].clear();
s2[b][i].clear();
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
YES WW WW NO YES BWW WWW WWW
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 31ms
memory: 3588kb
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 BB BB WW BB YES WW BB BB BW WW WW NO NO YES B W W B B W W W B W YES WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW WWWW YES WBW WWW WWW WWW WWW WWW WWW WWW YES W B W W YES BBBB WBBB YES BBBBBB WWWWWB YES WWWWW YES BWWWWW WWBBBB BBBWWW WWWWWW YES W YES BWB BBB WBB BBB WWB BBB BWW WWW...
result:
wrong answer ans finds the answer, but out doesn't (test case 7535)