QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#99065#5071. Check Pattern is Good1kriWA 2ms3380kbC++144.0kb2023-04-21 10:08:352023-04-21 10:08:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 10:08:38]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3380kb
  • [2023-04-21 10:08:35]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#define inf 1000000000
using namespace std;
struct FLOW{
	int n,m,s,t,u[100005],v[100005],w[100005],first[100005],nxt[100005];
	void init(int _s,int _t){
		n=_t,m=1,s=_s,t=_t;
		memset(first,0,sizeof(first));
		memset(nxt,0,sizeof(nxt));
		return;
	}
	void add(int a,int b,int c){
		int i=++m;
		u[i]=a,v[i]=b,w[i]=c;
		nxt[i]=first[u[i]],first[u[i]]=i;
		i=++m;
		u[i]=b,v[i]=a,w[i]=0;
		nxt[i]=first[u[i]],first[u[i]]=i;
		return;
	}
	int q[100005],head,tail,depth[100005],cur[100005];
	bool bfs(){
		for (int i=1;i<=n;i++)depth[i]=-1,cur[i]=first[i];
		depth[s]=0;
		head=tail=1;
		q[1]=s;
		while(head<=tail){
			int now=q[head];
			head++;
			for (int i=first[now];i;i=nxt[i])
				if (w[i]>0&&depth[v[i]]==-1){
					depth[v[i]]=depth[now]+1;
					q[++tail]=v[i];
					if (v[i]==t)return 1;
				}
		}
		return 0;
	}
	int dfs(int now,int in){
		if (now==t)return in;
		int out=0;
		for (int i=cur[now];i!=0&&in>0;i=nxt[i]){
			cur[now]=i;
			if (depth[v[i]]!=depth[now]+1||w[i]==0)continue;
			int qwq=dfs(v[i],min(in,w[i]));
			in-=qwq,out+=qwq;
			w[i]-=qwq,w[i^1]+=qwq;
		}
		return out;
	}
	int work(){
		int ans=0;
		while(bfs())ans+=dfs(s,inf);
		return ans;
	}
	int tot,a[100005],b[100005];
	int col[100005];
	void qwq_dfs(int now){
		col[now]=1;
		for (int i=first[now];i;i=nxt[i])
			if (w[i]>0&&col[v[i]]==0)qwq_dfs(v[i]);
		return;
	}
	void qwq(){
		tot=0;
		memset(col,0,sizeof(col));
		qwq_dfs(s);
		for (int i=1;i<=m;i++)
			if (col[u[i]]==1&&col[v[i]]==0){
				++tot;
				a[tot]=u[i],b[tot]=v[i];
			}
		return;
	}
}flow;
int testcase,n,m;
char a[105][105];
int book0[105][105],book1[105][105];
int id(int x,int y){
	return (x-1)*m+y;
}
int main(){
	scanf("%d",&testcase);
int qwq=0;
	while(testcase--){
		scanf("%d%d",&n,&m);
		for (int i=1;i<=n;i++){
			scanf("%s",a[i]+1);
		}
if (qwq==12){
cout<<n<<' '<<m<<endl;
for (int i=1;i<=n;i++){for (int j=1;j<=m;j++)cout<<a[i][j];cout<<endl;}
}
continue;
		int s=2*n*m+1,t=2*n*m+2;
		flow.init(s,t);
		int ans=0;
		for (int i=1;i<n;i++)
			for (int j=1;j<m;j++){
				int c=0;
				if (a[i][j]!='W'&&a[i][j+1]!='W'&&a[i+1][j]!='W'&&a[i+1][j+1]!='W'){
					c++;
					flow.add(s,id(i,j),1);
				}
				if (a[i][j]!='B'&&a[i][j+1]!='B'&&a[i+1][j]!='B'&&a[i+1][j+1]!='B'){
					c++;
					flow.add(n*m+id(i,j),t,1);
				}
				ans+=c;
				if (c>0)flow.add(id(i,j),n*m+id(i,j),c);
			}
		for (int i=1;i<n;i++)
			for (int j=1;j<m;j++){
				if (i<n-1){
					flow.add(id(i,j)+n*m,id(i+1,j),inf);
					flow.add(id(i+1,j)+n*m,id(i,j),inf);
				}
				if (j<m-1){
					flow.add(id(i,j)+n*m,id(i,j+1),inf);
					flow.add(id(i,j+1)+n*m,id(i,j),inf);
				}
				if (i<n-1&&j<m-1){
					flow.add(id(i,j)+n*m,id(i+1,j+1),inf);
					flow.add(id(i+1,j+1)+n*m,id(i,j),inf);
				}
			}
		ans-=flow.work();
		printf("%d\n",ans);
		flow.qwq();
		memset(book0,0,sizeof(book0));
		memset(book1,0,sizeof(book1));
		for (int i=1;i<=flow.tot;i++){
			if (flow.a[i]==s){
				int x=flow.b[i]/m+1,y=flow.b[i]%m;
				if (y==0)x--,y=m;
				book0[x][y]=1;
			}
			if (flow.b[i]==t){
				int x=(flow.a[i]-n*m)/m+1,y=(flow.a[i]-n*m)%m;
				if (y==0)x--,y=m;
				book1[x][y]=1;
			}
			if (flow.b[i]==flow.a[i]+n*m){
				int x=flow.b[i]/m+1,y=flow.b[i]%m;
				if (y==0)x--,y=m;
				book0[x][y]=book1[x][y]=1;
			}
		}
		for (int i=1;i<n;i++)
			for (int j=1;j<m;j++){
				if (book0[i][j]==0&&a[i][j]!='W'&&a[i][j+1]!='W'&&a[i+1][j]!='W'&&a[i+1][j+1]!='W')
					a[i][j]=a[i][j+1]=a[i+1][j]=a[i+1][j+1]='B';
				if (book1[i][j]==0&&a[i][j]!='B'&&a[i][j+1]!='B'&&a[i+1][j]!='B'&&a[i+1][j+1]!='B')
					a[i][j]=a[i][j+1]=a[i+1][j]=a[i+1][j+1]='W';
			}
		for (int i=1;i<=n;i++){
			for (int j=1;j<=m;j++){
				if (a[i][j]=='?')a[i][j]='B';
				if ((i+j)&1){
					if (a[i][j]=='B')a[i][j]='W';
					else if (a[i][j]=='W')a[i][j]='B';
				}
				printf("%c",a[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3380kb

input:

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

output:


result:

wrong output format Unexpected end of file - int32 expected (test case 1)