QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411350 | #5071. Check Pattern is Good | Made_in_Code | WA | 142ms | 3548kb | C++14 | 2.8kb | 2024-05-15 11:58:49 | 2024-05-15 11:58:49 |
Judging History
answer
#include <iostream>
#include <queue>
using namespace std;
const int kMaxN = 101, kEdge = 1e4, kReject = 1e8, kInf = 1e9;
const int kMove[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
struct E {
int p, d, w;
} e[kMaxN * kMaxN * 22];
struct V {
int d, et, nt;
} v[kMaxN * kMaxN * 3];
int o, n, m, k, s, t, ans;
char c[kMaxN][kMaxN];
queue<int> q;
int R(int x, int y, int z) {
return z * n * m + (x - 1) * m + y;
}
void AddEdge(int x, int y, int w) {
e[++k] = {v[x].et, y, w}, v[x].et = k;
e[++k] = {v[y].et, x, 0}, v[y].et = k;
}
bool Bfs() {
for (int i = 1; i <= t; i++) {
v[i].d = i == s, v[i].nt = v[i].et;
}
for (q.push(s); !q.empty(); q.pop()) {
for (int i = v[q.front()].et; i; i = e[i].p) {
if (e[i].w && !v[e[i].d].d) {
v[e[i].d].d = v[q.front()].d + 1;
q.push(e[i].d);
}
}
}
return v[t].d;
}
int Dfs(int x, int in) {
if (x == t) {
return in;
}
int out = 0;
for (int &i = v[x].nt; i && in; in && (i = e[i].p)) {
if (e[i].w && v[x].d + 1 == v[e[i].d].d) {
int t = Dfs(e[i].d, min(in, e[i].w));
e[i].w -= t, e[i ^ 1].w += t;
in -= t, out += t;
}
}
return out;
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
cin >> o;
while (o--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
if ((i + j & 1) && (c[i][j] != '?')) {
c[i][j] ^= 21;
}
}
}
for (int i = 1; i <= t; i++) {
v[i].et = 0;
}
s = n * m * 3 + 1, t = s + 1, k = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
AddEdge(s, R(i, j, 2), c[i][j] != 'B' ? kEdge : kReject);
AddEdge(R(i, j, 2), t, c[i][j] != 'W' ? kEdge : kReject);
}
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < m; j++) {
AddEdge(R(i, j, 0), R(i, j, 1), 1);
for (int u = 0; u < 4; u++) {
int _i = i + kMove[u][0], _j = j + kMove[u][1];
AddEdge(R(_i, _j, 2), R(i, j, 0), 1);
AddEdge(R(i, j, 1), R(_i, _j, 2), 1);
}
}
}
for (ans = 0; Bfs(); ans += Dfs(s, kInf)) {
}
cout << (n - 1) * (m - 1) + n * m * kEdge - ans << '\n';
for (int p = 1; p <= n; p++) {
for (int q = 1; q <= m; q++) {
int x = R(p, q, 2);
char ch = 'W';
for (int i = v[x].et; i; i = e[i].p) {
if (e[i].d == s && !e[i ^ 1].w) {
break;
} else if (e[i].d == t && !e[i].w) {
ch = 'B';
break;
}
}
if (p + q & 1) {
ch ^= 21;
}
cout << ch;
}
cout << '\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3548kb
input:
3 2 2 ?? ?? 3 3 BW? W?B ?BW 3 3 BW? W?W ?W?
output:
1 BW WB 1 BWB WBB BBW 4 BWB WBW BWB
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 142ms
memory: 3544kb
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:
3 BB BW WW WW BW WB BW WB BB 2 BW WB BW BW WW WB 9 WBBBWWB WBWBWWW BWBBWWB WBWWBWW BBWBBWB WWBBWWW BWBWBWB WWWWBBW BBWBBWW BBWBWBB 6 BWWBWWB WBBWWWB BWBBBBB BBBWBBB 0 B W B B B W W W B W 15 BWWW WBWB WWWW WBWW BWBW WWWW WWWW WWWW BWBW WBWW 8 WBW WBW BWB WBW WWW WBW BWB WWW 0 W B B W 1 BBBB WBWB 3 BW...
result:
wrong answer There are 3 check pattern in you output, but you answered 6 (test case 4)