QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359647#5071. Check Pattern is Goodeggegg185WA 2025ms9516kbC++143.3kb2024-03-20 19:41:472024-03-20 19:41:47

Judging History

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

  • [2024-03-20 19:41:47]
  • 评测
  • 测评结果:WA
  • 用时:2025ms
  • 内存:9516kb
  • [2024-03-20 19:41:47]
  • 提交

answer

#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
#define int long long
int head[100001],cur[100001],nxt[100001],wei[100001],frm[100010],to[100001],cnt = 2,level[100001],s,t;
int mappa[105][105];
const int inf = 0x3f3f3f3f;
void add(int u,int v,int w) {
	to[cnt] = v,frm[cnt] = u;
	wei[cnt] = w;
	nxt[cnt] = head[u];
	head[u] = cnt;
	cnt++;
	to[cnt] = u,frm[cnt] = v;
	wei[cnt] = 0;
	nxt[cnt] = head[v];
	head[v] = cnt;
	cnt++;
}
int bfs() {
	memset(level,-1,sizeof(level));
	memcpy(cur,head,sizeof(head));
	level[s] = 0;
	queue<int> q;
	q.push(s);
	while(!q.empty()) {
		int top = q.front();
		q.pop();
		for(int i = head[top]; i ; i = nxt[i]) {
			int tp = to[i];
			if(level[tp] == -1 && wei[i] > 0) {
				level[tp] = level[top] + 1;
				q.push(tp);
			}
		}
	}
	if(level[t] == -1) return 0;
	return 1;
}
int dfs(int now,int flow) {
	if(now == t) return flow;
	int remain = flow;
	for(int i = cur[now]; i ; i = nxt[i]) {
		cur[now] = i;
		int tp = to[i],w = wei[i];
		if(w > 0 && level[now]+1 == level[tp]) {
			int c = dfs(tp,min(w,remain));
			remain -= c;
			wei[i] -= c;
			wei[i^1] += c;
		}
	}
	return flow - remain;
}
int dinic() {
	int ans = 0;
	while(bfs()) {
		ans += dfs(s,inf);
	}
	return ans;
}
bool plc[100010];
void dfs2(int now) {
	plc[now] = true;
	for(int i = head[now]; i; i = nxt[i]) {
		if(!plc[to[i]] && wei[i]) dfs2(to[i]);
	}
}
//S is B is 0, T is W is 1
char ss[100010];
signed muin() {
	memset(plc,0,sizeof(plc));
	memset(head,0,sizeof(head));
	cnt = 2; return 0;
}
signed moin() {
	int n,m; cin >> n >> m; n--,m--;
	s = 2*n*m+1,t = 2*n*m+2; int tot = 0;
	for(int i = 1; i <= n+1; i++) {
		cin >> (ss+1); for(int j = 1; j <= m+1; j++) {
			mappa[i][j] = (ss[j] == 'W')^((i+j)&1);
			if(ss[j] == '?') mappa[i][j] = -1;
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(mappa[i][j] != 1 && mappa[i+1][j] != 1 && mappa[i][j+1] != 1 && mappa[i+1][j+1] != 1) add(s,(i-1)*m+j,1),tot++;
			if(mappa[i][j] != 0 && mappa[i+1][j] != 0 && mappa[i][j+1] != 0 && mappa[i+1][j+1] != 0) add(n*m+(i-1)*m+j,t,1),tot++;
			add((i-1)*m+j,n*m+(i-1)*m+j,inf);
			if(i < n) add((i-1)*m+j,n*m+i*m+j,inf),add(i*m+j,n*m+(i-1)*m+j,inf);
			if(j < m) add((i-1)*m+j,n*m+(i-1)*m+(j+1),inf),add((i-1)*m+(j+1),n*m+(i-1)*m+j,inf);
			if(i < n && j < m) add((i-1)*m+j,n*m+i*m+(j+1),inf),add(i*m+(j+1),n*m+(i-1)*m+j,inf);
			if(i > 1 && j < m) add((i-1)*m+j,n*m+(i-2)*m+(j+1),inf),add((i-2)*m+(j+1),n*m+(i-1)*m+j,inf);
		}
	}
	printf("%lld\n",tot-dinic()); dfs2(s);
	if(m) for(int i = 2; i <= cnt; i++) {
		int x = frm[i],y = to[i]-n*m;
		int x1 = x/m+1,y1 = x%m; if(y1 == 0) x1--,y1 = m;
		int x2 = y/m+1,y2 = y%m; if(y2 == 0) x2--,y2 = m;
		if(plc[x] == plc[y]) {
			if(frm[i] == s) mappa[x2][y2] = mappa[x2][y2+1] = mappa[x2+1][y2] = mappa[x2+1][y2+1] = 0;
			if(to[i] == t) mappa[x1][y1] = mappa[x1][y1+1] = mappa[x1+1][y1] = mappa[x1+1][y1+1] = 1;
		}
	}
	for(int i = 1; i <= n+1; i++) {
		for(int j = 1; j <= m+1; j++) {
			if(mappa[i][j] == -1) mappa[i][j] = 0;
			mappa[i][j] ^= ((i+j)&1);
			putchar(mappa[i][j]?'W':'B');
		} putchar('\n');
	}
	return 0;
}
signed main() {
	cin.tie(0)->sync_with_stdio(false);
	int T; cin >> T;
	while(T--) {muin();moin();}
	return 0;
}

詳細信息

Test #1:

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

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: 2025ms
memory: 9516kb

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
BWWBWBB
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
WWB
0
W
B
B
W
1
BBBB
WWBB
3
BW...

result:

wrong answer There are 3 check pattern in you output, but you answered 6 (test case 4)