QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#596232#7857. (-1,1)-SumpleteDelovWA 1ms5712kbC++142.5kb2024-09-28 15:22:272024-09-28 15:22:31

Judging History

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

  • [2024-09-28 15:22:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5712kb
  • [2024-09-28 15:22:27]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;typedef unsigned long long ull; typedef double db;typedef long double ldb;
#define fre(x) freopen(#x ".in","r",stdin),freopen(#x ".out","w",stdout)
#define Rep(i,a,b) for(int i=a;i<=b;++i) 
#define Dwn(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define mair make_pair
#define fir first
#define sec second
using namespace std;

const int maxn=4e3+10,INF=INT_MAX>>1;

int n;
char s[maxn];
int R[maxn],C[maxn],sR[maxn],sC[maxn];
int S,T;
int a[maxn][maxn];

struct Graph_Net{
	struct eg{ int to,next;int cap; }e[maxn*maxn*2+maxn*4];
	int len,head[maxn*2];
	Graph_Net(){ len=1; }
	void lqx(int from,int to,int cap)
	{ e[++len].to=to;e[len].next=head[from];e[len].cap=cap;head[from]=len; }
	void Set_c(int u,int v,int w){ lqx(u,v,w),lqx(v,u,0); }
	int dep[maxn*2],cur[maxn*2];
	int q[maxn*2],l,r;
	bool bfs(int s,int t){
		memset(dep,0,sizeof(dep)); dep[s]=1;
		l=1,r=1;q[1]=s; cur[s]=head[s];
		while(l<=r){
			s=q[l];++l;
			for(int i=head[s];i;i=e[i].next){
				int v=e[i].to;
				if(dep[v] || !e[i].cap)continue;
				dep[v]=dep[s]+1;
				cur[v]=head[v];
				if(v==t)return true;
				q[++r]=v;
			}
		}
		return false;
	}
	int dfs(int u,int flow){
		if(u==T || !flow)return flow;
		int rest=flow,res;
		for(int &i=cur[u],v;i;i=e[i].next){
			v=e[i].to;
			if(!e[i].cap || dep[v]!=dep[u]+1)continue;
			res=dfs(v,min(rest,e[i].cap));
			if(res==0)dep[v]=0;
			rest-=res; e[i].cap-=res,e[i^1].cap+=res;
			if(rest<=0)break;
		}
		return flow-rest;
	}
	int Dinic(int s,int t){ int res=0;while(bfs(s,t))res+=dfs(s,INF); return res; }
	void Build(){
		Rep(u,1,n){
			for(int i=head[u];i;i=e[i].next)if(e[i].to!=S){
				int v=e[i].to-n;
				if(e[i].cap==0)a[u][v]^=1;
			}
		}
	}
}G;

void solve(){
	cin>>n;
	Rep(i,1,n){
		cin>>s;
		for(int j=0;j<n;++j)a[i][j+1]=(s[j]=='+'),sR[i]+=a[i][j+1],sC[j+1]+=a[i][j+1];
	}
	Rep(i,1,n)cin>>R[i];
	Rep(i,1,n)cin>>C[i];
	Rep(i,1,n)if(sR[i]<R[i] || sC[i]<C[i])return cout<<"No\n",void();
	S=1,T=n+n+2;
	int sum=0,sam=0;
	Rep(i,1,n){
		G.Set_c(S,i+1,sR[i]-R[i]);
		sum+=sR[i]-R[i];
		sam+=sC[i]-C[i];
	}
	Rep(i,1,n)Rep(j,1,n)G.Set_c(i,j+n,1);
	Rep(i,1,n)G.Set_c(i+n+1,T,sC[i]-C[i]);

	if(sum!=sam)return cout<<"No\n",void();
	int res=G.Dinic(S,T);
	if(res!=sum)return cout<<"No\n",void();
	G.Build();
	cout<<"Yes\n";
	Rep(i,1,n){
		Rep(j,1,n)cout<<a[i][j];
		cout<<"\n";
	}
}

int main (){ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);return solve(),0; }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5712kb

input:

3
+-+
-++
+-+
1 1 1
1 -1 3

output:

Yes
110
011
100

result:

wrong answer wrong sum at row 1