QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#735937 | #5071. Check Pattern is Good | lalaouye | WA | 17ms | 4428kb | C++14 | 3.6kb | 2024-11-11 22:56:15 | 2024-11-11 22:56:16 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i (l); i <= r; ++ i)
#define rrp(i, l, r) for (int i (r); i >= l; -- i)
#define pii pair <int, int>
#define eb emplace_back
#define ls p << 1
#define rs ls | 1
#define inf 1000000000
using namespace std;
constexpr int N = 100 + 5;
typedef unsigned long long ull;
typedef long long ll;
inline ll rd () {
ll x = 0, f = 1;
char ch = getchar ();
while (! isdigit (ch)) {
if (ch == '-') f = -1;
ch = getchar ();
}
while (isdigit (ch)) {
x = (x << 1) + (x << 3) + ch - 48;
ch = getchar ();
}
return x * f;
}
int n, m;
char s[N][N];
int id[N][N][2];
vector <int> e[N * N << 1];
int col[N * N << 1], match[N * N << 1];
int vis[N * N << 1];
int stk[N * N << 1], top;
int chg[N * N << 1];
bool dfs (int u) {
for (auto v : e[u]) {
if (vis[v]) continue;
vis[v] = 1; stk[++ top] = v;
if (! match[v] || dfs (match[v])) return match[v] = u, 1;
} return 0;
}
void dfs (int u, int now) {
if (col[u] != -1) return ;
col[u] = now;
for (auto v : e[u]) dfs (v, ! now);
}
void solve () {
n = rd (), m = rd ();
rep (i, 1, n) scanf ("%s", s[i] + 1);
rep (i, 1, n) rep (j, 1, m) rep (k, 0, 1) id[i][j][k] = 0;
int tot = 0, ans = 0;
rep (i, 1, n - 1) {
rep (j, 1, m - 1) {
if (s[i][j] == '?' || s[i][j + 1] == '?' || s[i + 1][j] == '?' || s[i + 1][j + 1] == '?') {
if (s[i][j] != 'W' && s[i + 1][j] != 'B' && s[i][j + 1] != 'B' && s[i + 1][j + 1] != 'W') id[i][j][0] = ++ tot;
if (s[i][j] != 'B' && s[i + 1][j] != 'W' && s[i][j + 1] != 'W' && s[i + 1][j + 1] != 'B') id[i][j][1] = ++ tot;
} else {
ans += s[i][j] == s[i + 1][j + 1] && s[i][j] != s[i + 1][j] && s[i][j] != s[i][j + 1];
}
}
}
rep (i, 1, n - 1) {
rep (j, 1, m - 1) {
rep (k, 0, 1) {
if (! id[i][j][k]) continue;
if (id[i][j][! k]) e[id[i][j][k]].eb (id[i][j][! k]);
if (id[i][j + 1][k]) e[id[i][j][k]].eb (id[i][j + 1][k]), e[id[i][j + 1][k]].eb (id[i][j][k]);
if (id[i + 1][j][k]) e[id[i][j][k]].eb (id[i + 1][j][k]), e[id[i + 1][j][k]].eb (id[i][j][k]);
if (id[i + 1][j + 1][! k]) e[id[i][j][k]].eb (id[i + 1][j + 1][! k]), e[id[i + 1][j + 1][! k]].eb (id[i][j][k]);
}
}
}
fill (col + 1, col + tot + 1, -1);
rep (i, 1, tot) {
if (col[i] == -1) dfs (i, 0);
}
rep (i, 1, tot) {
if (! col[i]) ans -= dfs (i);
while (top) vis[stk[top --]] = 0;
}
rep (i, 1, tot) if (col[i]) match[match[i]] = i;
queue <int> q;
rep (i, 1, tot) vis[i] = -1;
rep (i, 1, tot) {
if (! match[i]) {
vis[i] = 1;
for (auto v : e[i]) if (vis[v] == -1) vis[v] = 0, q.push (v);
}
}
while (! q.empty ()) {
int u = q.front ();
q.pop ();
for (auto v : e[u]) {
if (vis[v] == -1) {
vis[v] = 1;
for (auto w : e[v]) {
if (vis[w] == -1) vis[w] = 0, q.push (w);
}
}
}
}
rep (i, 1, tot) if (vis[i] == -1 && vis[match[i]] == -1 && col[i] == 0) vis[i] = 1;
rep (i, 1, n - 1) {
rep (j, 1, m - 1) {
if (vis[id[i][j][0]] == 1) s[i][j] = 'B', s[i + 1][j] = 'W', s[i][j + 1] = 'W', s[i + 1][j + 1] = 'B';
if (vis[id[i][j][1]] == 1) s[i][j] = 'W', s[i + 1][j] = 'B', s[i][j + 1] = 'B', s[i + 1][j + 1] = 'W';
}
}
printf ("%d\n", ans + tot);
rep (i, 1, n) {
rep (j, 1, m) if (s[i][j] != '?') putchar (s[i][j]); else putchar ('B');
puts ("");
}
rep (i, 1, tot) e[i].clear (), match[i] = 0, vis[i] = 0;
}
int main () {
// freopen ("1.in", "r", stdin);
// freopen ("1.out", "w", stdout);
for (int T (rd ()); T; -- T) solve ();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4352kb
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: 17ms
memory: 4428kb
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 BB 9 WBBBWBB BWBBWWW WBWBWWB BWWWBWB BBWBBWB WWBWWWB BWBWBBW WWWWBBW BBWBBWW BBWBWBB 6 BWWBWWB WBBWWWB BWWBBBW BBBWBBB 0 B W B B B W W W B B 15 BWWW WBWB WWWB WBBW BWWB BWBW WBWB BWBW WBWW BWBW 8 WBW WWB WBW BWB WBW WBW BWB BWB 0 W B B B 1 BBWB WWBB 3 BW...
result:
wrong answer There are 4 check pattern in you output, but you answered 5 (test case 18)