QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694867#5071. Check Pattern is GoodWorld_CreaterWA 78ms5696kbC++173.4kb2024-10-31 18:50:572024-10-31 18:50:57

Judging History

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

  • [2024-10-31 18:50:57]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:5696kb
  • [2024-10-31 18:50:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int t,n,m;
string a[105];
char ans[105][105];
int s,e,nxt[500005],head[20005],go[500005],fl[500005],k=1;
int cur[20005],lvl[20005],vis[20005];
const int xr[]={0,0,0,1,1,1,-1,-1,-1},yr[]={0,1,-1,0,1,-1,0,1,-1};
void add(int u,int v,int w)
{
	nxt[++k]=head[u];
	head[u]=k;
	go[k]=v;
	fl[k]=w;
}
void Add(int u,int v,int w)
{
	// cerr<<"???"<<u<<" "<<v<<" "<<w<<"\n";
	add(u,v,w);
	add(v,u,0);
}
int get(int op,int x,int y)
{
	return op*n*m+(x-1)*m+y;
}
bool bfs()
{
	for(int i=s;i<=e;i++)
	{
		cur[i]=head[i];
		lvl[i]=inf;
	}
	lvl[s]=0;
	queue<int> q;
	q.emplace(s);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=head[x];i;i=nxt[i])
		{
			if(!fl[i]) continue ;
			int g=go[i];
			if(lvl[g]>lvl[x]+1)
			{
				lvl[g]=lvl[x]+1;
				q.emplace(g);
				if(g==e) return 1;
			}
		}	
	}
	return 0;
}
int dfs(int x,int flow)
{
	if(x==e) return flow;
	int res=0,res1=0;
	for(int &i=cur[x];i;i=nxt[i])
	{
		int g=go[i];
		if(!fl[i]||lvl[g]!=lvl[x]+1) continue ;
		res1=dfs(g,min(flow,fl[i]));
		flow-=res1;
		res+=res1;
		fl[i]-=res1;
		fl[i^1]+=res1;
		if(!flow) return res;
	}
	return res;
}
void find(int x)
{
	if(vis[x]) return ;
	vis[x]=1;
	for(int i=head[x];i;i=nxt[i])
	{
		int g=go[i];
		if(!fl[i]) continue ;
		find(g);
	}
}
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		s=0;
		e=n*m*2;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			a[i]=" "+a[i];
			for(int j=1;j<=m;j++)
			{
				ans[i][j]=0;
				if((i+j)&1) 
				{
					if(a[i][j]=='B') a[i][j]='W';
					else if(a[i][j]=='W') a[i][j]='B';
				}
			}
		}
		int res=0;
		for(int i=1;i<n;i++)
		{
			for(int j=1;j<m;j++)
			{
				bool fl=1;
				for(int d1=0;d1<2;d1++)
				{
					for(int d2=0;d2<2;d2++)
					{
						fl&=a[i+d1][j+d2]!='B';
					}
				}
				if(fl)
				{
					res++;
					Add(s,get(0,i,j),1);
				}
				fl=1;
				for(int d1=0;d1<2;d1++)
				{
					for(int d2=0;d2<2;d2++)
					{
						fl&=a[i+d1][j+d2]!='W';
					}
				}
				if(fl)
				{
					res++;
					Add(get(1,i,j),e,1);
				}
				for(int d=0;d<9;d++)
				{
					int nx=i+xr[d],ny=j+yr[d];
					if(nx<1||ny<1||nx>=n||ny>=m) continue ;
					Add(get(0,i,j),get(1,nx,ny),inf);
				}
			}
		}
		while(bfs()) res-=dfs(s,inf);
		find(s);
		cout<<res<<"\n";
		for(int i=head[s];i;i=nxt[i])
		{
			int g=go[i];
			if(!vis[g]) continue ;
			int y=(g-1)%m+1,x=(g-1)/m+1;
			// cerr<<g<<" "<<x<<" "<<y<<"\n";
			for(int s1=0;s1<2;s1++)
			{
				for(int s2=0;s2<2;s2++)
				{
					ans[x+s1][y+s2]='W';
				}
			}
		}
		for(int i=head[e];i;i=nxt[i])
		{
			int g=go[i];
			if(vis[g]) continue ;
			int y=(g-n*m-1)%m+1,x=(g-n*m-1)/m+1;
			// cerr<<g<<" "<<x<<" "<<y<<"\n";
			for(int s1=0;s1<2;s1++)
			{
				for(int s2=0;s2<2;s2++)
				{
					ans[x+s1][y+s2]='B';
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(!ans[i][j]) ans[i][j]='B';
				if(a[i][j]!='?') ans[i][j]=a[i][j];
				if((i+j)&1)
				{
					if(ans[i][j]=='W') ans[i][j]='B';
					else if(ans[i][j]=='B') ans[i][j]='W';
				}
				cout<<ans[i][j];
				// if(i>1&&j>1) res-=(ans[i][j]==ans[i-1][j-1])&&(ans[i-1][j]==ans[i][j-1])&&(ans[i][j]!=ans[i][j-1]);
			}
			cout<<"\n";
		}
		cerr<<res<<"\n";
		for(int i=s;i<=e;i++)
		{
			head[i]=0;
		}
		k=0;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5624kb

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: 78ms
memory: 5696kb

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
13
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)