QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#490743#5070. Check Pattern is BadpavementWA 31ms3608kbC++172.6kb2024-07-25 16:19:192024-07-25 16:19:19

Judging History

你现在查看的是最新测评结果

  • [2024-07-25 16:19:19]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:3608kb
  • [2024-07-25 16:19:19]
  • 提交

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());
			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();
			}
		}
	}
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

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: 3608kb

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 1650)