QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359149#5071. Check Pattern is GoodDoqeWA 0ms3748kbC++142.8kb2024-03-20 13:55:442024-03-20 13:55:44

Judging History

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

  • [2024-03-20 13:55:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3748kb
  • [2024-03-20 13:55:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace Flow
{
const int N=4e4+10,M=3e5+10;
int hd[N],to[M<<1],nx[M<<1],W[M<<1],tt=1,po;
void add(int u,int v,int w){to[++tt]=v,W[tt]=w,nx[tt]=hd[u],hd[u]=tt;}
void link(int u,int v,int w){add(u,v,w),add(v,u,0);}
int q[N],l,r,cur[N],dep[N],S,T,n,m;
bool bfs()
{
	memset(dep,0,sizeof(int)*(po+10));
	memcpy(cur,hd,sizeof(int)*(po+10));
	q[l=r=1]=S;dep[S]=1;
	while(l<=r)
	{
		int u=q[l++];
		for(int i=hd[u];i;i=nx[i])
		{
			int v=to[i];
			if(W[i]&&!dep[v])
			{
				q[++r]=v,dep[v]=dep[u]+1;
				if(v==T)return true;
			}
		}
	}
	return dep[T];
}
int dfs(int u,int f)
{
	if(u==T)return f;
	int r=0,k;
	for(int&i=cur[u];i&&f;i=nx[i])
	{
		int v=to[i];
		if(W[i]&&dep[v]==dep[u]+1)
		{
			k=dfs(v,min(W[i],f-r));
			r+=k;W[i]-=k,W[i^1]+=k;if(f==r)break;
		}
	}
	if(f==r)dep[u]=0;
	return f-r;
}
int Dinic()
{
	int flow=0;
	while(bfs())flow+=dfs(S,0x3f3f3f3f);
	return flow;
}
int via[N];
void ini()
{
	memset(via,0,sizeof(int)*(po+10));
	memset(hd,0,sizeof(int)*(po+10));
	tt=1;po=0;
}
void dfs(int u)
{
	via[u]=1;
	for(int i=hd[u];i;i=nx[i])
	{
		int v=to[i];
		if(W[i]&&!via[v])dfs(v);
	}
}
}
const int N=110;
int I[N][N],n,m;
char s[N][N],trans[128];
int main()
{
	cin.tie(0)->sync_with_stdio(0);
	int T;
	cin>>T;
	trans['W']='B';
	trans['B']='W';
	trans['?']='?';
	while(T--)
	{
		cin>>n>>m;Flow::ini();
		for(int i=1;i<=n;++i)cin>>s[i]+1;
		int cnt=1;Flow::S=1,Flow::T=2;Flow::po=2; 
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				I[i][j]=(cnt+=2);
		cnt+=2;
		int X=0;
		for(int i=n;i;--i)
			for(int j=m;j;--j)
			{
				if(i+j&1)s[i][j]=trans[s[i][j]];
				if(s[i][j]=='?')
				{
					Flow::link(Flow::S,I[i][j],1);
					Flow::link(I[i][j],I[i][j]+1,100000);
					Flow::link(I[i][j]+1,Flow::T,1);++X;
				}
			}
		for(int i=1;i<n;++i)
			for(int j=1;j<m;++j)
			{
				if(	s[i][j]!='W'&&s[i+1][j]!='W'&&
					s[i][j+1]!='W'&&s[i+1][j+1]!='W')
					{
						Flow::link(Flow::S,++cnt,1);
						Flow::link(cnt,I[i][j],1);
						Flow::link(cnt,I[i][j+1],1);
						Flow::link(cnt,I[i+1][j],1);
						Flow::link(cnt,I[i+1][j+1],1);
						++X;
					}
				
				if(	s[i][j]!='B'&&s[i+1][j]!='B'&&
					s[i][j+1]!='B'&&s[i+1][j+1]!='B')
					{
						Flow::link(++cnt,Flow::T,1);
						Flow::link(I[i][j]+1,cnt,1);
						Flow::link(I[i][j+1]+1,cnt,1);
						Flow::link(I[i+1][j]+1,cnt,1);
						Flow::link(I[i+1][j+1]+1,cnt,1);
						++X;
					}
			}
		Flow::po=cnt+1;
		int ans=Flow::Dinic();
		cout<<X-ans<<'\n';
		Flow::dfs(Flow::S);
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)if(s[i][j]=='?')
				if(!Flow::via[I[i][j]])s[i][j]='W';
				else s[i][j]='B';
		for(int i=1;i<=n;++i,cout<<"\n")
			for(int j=1;j<=m;++j)
			{
				char c=s[i][j];
				if(i+j&1)c=trans[c];
				cout<<c;
			}
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3748kb

input:

3
2 2
??
??
3 3
BW?
W?B
?BW
3 3
BW?
W?W
?W?

output:

-1061109556
WB
BW
-2122219126
BWW
WBB
WBW
-1061109555
BWB
WBW
BWB

result:

wrong answer Integer parameter [name=ans] equals to -1061109556, violates the range [0, 4] (test case 1)