QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#790516#5071. Check Pattern is Goodlouhao088WA 335ms8180kbC++232.6kb2024-11-28 13:01:232024-11-28 13:01:28

Judging History

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

  • [2024-11-28 13:01:28]
  • 评测
  • 测评结果:WA
  • 用时:335ms
  • 内存:8180kb
  • [2024-11-28 13:01:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
inline int read(){
	char ch=getchar();int x=0;bool f=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
	for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
	if(f==1)x=-x;return x;
}
const int maxn=1e5+5,inf=1e6;
int n,m,flag[105][105],ans,T,s,t;
char a[maxn];

struct Dinic
{
	int head[maxn],to[maxn*4],nex[maxn*4],w[maxn*4];
	int cnt=1,dis[maxn],cur[maxn],vis[maxn],sum,maxflow;
	void add(int x,int y,int z){to[++cnt]=y,w[cnt]=z,nex[cnt]=head[x],head[x]=cnt;
	to[++cnt]=x,w[cnt]=0,nex[cnt]=head[y],head[y]=cnt;}
	void clear(){
		for(int i=1;i<=t;i++)head[i]=cur[i]=vis[i]=0;
		cnt=1,maxflow=0;
	}
	bool bfs()
	{
		for(int i=1;i<=t;i++)dis[i]=-1;
		queue<int>q;
		q.push(s);dis[s]=0;
		memcpy(cur,head,sizeof head);
		while(!q.empty()){
			int x=q.front();q.pop();
			for(int i=head[x];i;i=nex[i]){
				if(dis[to[i]]==-1&&w[i]){q.push(to[i]);dis[to[i]]=dis[x]+1;}
			}
		}
		return dis[t]!=-1;
	}
	int dfs(int x,int flow)
	{
		if(x==t)return flow;int sum=0;
		for(int i=cur[x];i&&flow;i=nex[i]){cur[x]=i;
			if(dis[to[i]]==dis[x]+1&&w[i]){
				int num=dfs(to[i],min(flow,w[i]));
				flow-=num,w[i]-=num;w[i^1]+=num;sum+=num;
			}
		}
		return sum;
	}
	void work()
	{
		while(bfs())maxflow+=dfs(s,inf);
		for(int i=head[s];i;i=nex[i]){
			int u=(to[i]-1)/m+1,v=(to[i]-1)%m+1;
			if(u>n)continue;
			//cout<<u<<" "<<v<<" "<<w[i]<<endl;
			if(w[i]>0){
				flag[u][v]=1;
				
			}
		}
	}
}G;
void add(int x,int y,int z){G.add(x,y,z);}
int id(int x,int y){return (x-1)*m+y;}
void solve(){
	n=read(),m=read();
	G.clear();
	s=n*m+(n-1)*(m-1)*2+1;t=s+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)flag[i][j]=0;
	int sum=(n-1)*(m-1)*2,tot=n*m;
	for(int i=1;i<=n;i++){
		scanf("%s",a+1);
		for(int j=1;j<=m;j++){
			if((i+j)%2==0){
				if(a[j]=='B')a[j]='W';
				else if(a[j]=='W')a[j]='B';
			}
			if(a[j]=='B')add(s,id(i,j),inf);
			if(a[j]=='W')add(id(i,j),t,inf);
			if(a[j]=='?')add(id(i,j),t,1),add(s,id(i,j),1),sum++;
		}
	}
	for(int i=1;i<n;i++)
		for(int j=1;j<m;j++){
			++tot;
			add(s,tot,1);
			add(tot,id(i,j),inf);
			add(tot,id(i+1,j),inf);
			add(tot,id(i,j+1),inf);
			add(tot,id(i+1,j+1),inf);
			++tot;
			add(tot,t,1);
			add(id(i,j),tot,inf);
			add(id(i+1,j),tot,inf);
			add(id(i,j+1),tot,inf);
			add(id(i+1,j+1),tot,inf);	
		}
	G.work();
	ans=sum-G.maxflow;
	cout<<ans<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if((i+j)%2==0)flag[i][j]^=1;
			if(flag[i][j])putchar('B');
			else putchar('W');
		}
		puts("");
	}
}
signed main(){
	T=read();
	while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 335ms
memory: 8032kb

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)