QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#595932#7857. (-1,1)-SumpleteDelovTL 21ms27512kbC++142.6kb2024-09-28 14:48:122024-09-28 14:48:13

Judging History

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

  • [2024-09-28 14:48:13]
  • 评测
  • 测评结果:TL
  • 用时:21ms
  • 内存:27512kb
  • [2024-09-28 14:48:12]
  • 提交

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;
int a[maxn][maxn];
char s[maxn];
int R[maxn],C[maxn],sR[maxn],sC[maxn];
int S,T;

struct Graph_Net{
	struct eg{ int from,to,next;ll cap; }e[maxn*maxn*2+maxn*4];
	int len,head[maxn*2];
	Graph_Net(){ len=1; }
	void init(){ len=1;memset(head,0,sizeof(head));memset(e,0,sizeof(e)); }
	void lqx(int from,int to,ll cap)
	{ e[++len].from=from;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];
	queue<int>q;
	bool bfs(int s,int t){
		memset(dep,0,sizeof(dep)); dep[s]=1;
		while(!q.empty())q.pop(); q.push(s); cur[s]=head[s];
		while(!q.empty()){
			s=q.front();q.pop();
			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.push(v);
			}
		}
		return false;
	}
	ll dfs(int u,ll flow){
		if(u==T || !flow)return flow;
		ll rest=flow;
		for(int &i=cur[u];i;i=e[i].next){
			int v=e[i].to;
			if(!e[i].cap || dep[v]!=dep[u]+1)continue;
			ll 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;
	}
	ll Dinic(int s,int t){ ll 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=n+n+1,T=n+n+2;
	int sum=0,sam=0;
	Rep(i,1,n){
		G.Set_c(S,i,sR[i]-R[i]);
		G.Set_c(i+n,T,sC[i]-C[i]);
		sum+=sR[i]-R[i];
		sam+=sC[i]-C[i];
	}
	if(sum!=sam)return cout<<"No\n",void();
	Rep(i,1,n)Rep(j,1,n)G.Set_c(i,j+n,1);
	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: 100
Accepted
time: 1ms
memory: 5612kb

input:

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

output:

Yes
001
001
111

result:

ok n=3

Test #2:

score: 0
Accepted
time: 1ms
memory: 5684kb

input:

3
---
-++
+++
-2 -1 0
-2 -1 0

output:

Yes
110
100
000

result:

ok n=3

Test #3:

score: 0
Accepted
time: 1ms
memory: 5904kb

input:

3
+-+
-++
++-
1 0 2
2 2 -1

output:

No

result:

ok n=3

Test #4:

score: 0
Accepted
time: 1ms
memory: 5556kb

input:

1
-
-1
1

output:

No

result:

ok n=1

Test #5:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

1
-
0
0

output:

Yes
0

result:

ok n=1

Test #6:

score: 0
Accepted
time: 1ms
memory: 7976kb

input:

20
+-------+-----+++-++
-+-++++----++-++-++-
-+++--+---+--+-++---
-+++-+--+----++---+-
+++-+-++++++-+-+---+
-++-----+----++++++-
+-++--+++++-++-+----
+-+----+---+-+++--+-
+++++-+++++----+--+-
------++++---+--++--
++++--------++++--+-
-+-+-++++-+-++-++--+
---+-++---+-++-++---
+-++++-++----+-+++--
+-+...

output:

Yes
01110001100000110100
10101101010110110111
10000001011001011111
10000111010001101101
11011100001101010001
10011111010001111110
01001100001011010111
10111110111101110110
10000100000000010111
00011100001001011001
00001111111111100111
01011000010111001100
00010110000111101101
10111101101111101011
00...

result:

ok n=20

Test #7:

score: 0
Accepted
time: 2ms
memory: 8208kb

input:

100
++++-+-+--++++++-+--+--++-+-+--+++++-+++---+-+-+-++-+-+++-------+-++--+-++--+--+++++-++-+---+--+--++
-++--++-+-++++-+---++-+-+-+-+-+-+-+-+--+-+--+--+++---+--+-----+-----+-++-++-+-++++++--+-+++-+++-++++
--+---++-++--++-+++-------+--+-++------+-----+--+----++++++++-+--+++++--++--+-+-+++---+--+++-+...

output:

Yes
0000101011100011010010011010100111110111000101010110101110000000101100101100100111110110101101101100
1001100101100001000110101010101010101001010010011100010010000010000010110110101111110010111011101000
1101110010111010111000000010010110000001000001001000011111111010011111001100101011100010011110...

result:

ok n=100

Test #8:

score: 0
Accepted
time: 21ms
memory: 27512kb

input:

500
--+-+-+-++-----+++--+-+++-+---+-+-------+++--++++++-+--++--+-+-++++-++++--++--+---++--++----++--+---++-++--+-----+-+---++-++++-+++++++---++-++--+-++++-+----++-+++-+++---+--+++-+--++-++--+++++++-+++--+---+---+-+---++-+-+--+-+++-++-----+++-++-+++-+-++--++++++-+-++-+++---++-+++-++----+--+++----++++...

output:

Yes
11010101001111100011010001011101011111110001100000010110011010100001000011001101110011001111001101110010010100000101000110111101111111000110110010111101000011011101110001001110100110110011111110111001000101101011100101011010001001111100010010001010011000000101001000111001000100111101100011110000...

result:

ok n=500

Test #9:

score: -100
Time Limit Exceeded

input:

4000
-++-+-+-+--+-++++---+-++------++---+-+++--+++--+++++++---+-++-+++++++----+---+++-++--++---+-++--+----+---+--++-+-+-+-----+-+---++-++--+---+++-++++-+-----++--++-++---++-+--+++-+--+--+-+-++-+++--++---+++-+-+---+++-++-+-++-+-+++---+++---+-+--++---+-+---+--+++--+----+-+--++---+-----+-+--+----+-+++-...

output:

Yes
10010101011010000111010011111100111010001100011000000011101001000000011110111000100110011101001101111011101100101010111110101110010011011100010000101111100110011011100101100010110110101001010110011100010101110001001010100100110100011101011001110101110110001101011010110011101111101011011100101011...

result: