QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728699#7857. (-1,1)-SumpleteAshbourneRE 0ms3956kbC++233.7kb2024-11-09 15:42:092024-11-09 15:42:10

Judging History

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

  • [2024-11-09 15:42:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3956kb
  • [2024-11-09 15:42:09]
  • 提交

answer

#include<bits/stdc++.h>
const int N = 10005;
const int INF = 0x3f3f3f3f;
using namespace std;
int s, t, tot = 1, cnt;
struct Edge{
        int next, to, cap, flow; 
}edge[N * 100];
int head[N];
void add(int u, int v, int w, int rw = 0){
        edge[++tot] = {head[u], v, w, 0};
    head[u] = tot;
    edge[++tot] = {head[v], u, 0, 0};
        head[v] = tot;
}
int maxflow = 0;
int dep[N], cur[N];
bool bfs(){
        queue<int> q;
        memset(dep, 0, sizeof (dep[0]) * (cnt + 1));
        dep[s] = 1;
        q.push(s);
        while(q.size()){
                int u = q.front();
                q.pop();
                for(int i = head[u]; i; i = edge[i].next){
                        int v = edge[i].to;
                        if((!dep[v]) && (edge[i].cap > edge[i].flow)){
                                dep[v] = dep[u] + 1;
                                if(v == t) return 1;
                                q.push(v);
                        }
                }
        }
        return 0;
}
int dfs(int u, int flow){
        if((u == t) || (!flow)) return flow;
        int ret = 0;
        for(int &i = cur[u]; i; i = edge[i].next){
                int v = edge[i].to, d;
                if(dep[v] != dep[u] + 1) continue;
                d = dfs(v, min(flow - ret, edge[i].cap - edge[i].flow));
                if(d){
                        ret += d;
                        edge[i].flow += d;
                        edge[i ^ 1].flow -= d;
                        if(ret == flow) return ret;
                }
        }

        return ret;
}
void dinic(){
        while(bfs()){
                memcpy(cur, head, sizeof (head[0]) * (cnt + 1));
                maxflow += dfs(s, INF);
        }
}
void solve(){
        memset(head, 0, sizeof head);
        // memset(dat, 0, sizeof dat);
        // memset(vis, 0, sizeof vis);
        tot = 1; // this is important
		int n;
        cin >> n;
        s = 2 * n + 1; t = 2 * n + 2;
        int x = 0, y = 0;
        for(int i = 1; i <= n; ++ i)
        	for(int j = 1; j <= n; ++ j){
        		char ch;
        		cin >> ch;
        		if(ch == '+'){
        			add(i, j + n, 1);
        		}else{
        			add(j + n, i, 1);
        		}
        	}
        int ans = 0;
        vector<int> a(n + 1), b(n + 1);
        for(int i = 1; i <= n; ++ i) cin >> a[i], x += a[i];
        for(int i = 1; i <= n; ++ i) cin >> b[i], y += b[i];
        for(int i = 1; i <= n; ++ i){
        	if(a[i] > 0) ans += a[i];
        	if(a[i] > 0){
        		add(s, i, a[i]);
        	}else add(i, t, -a[i]);
        }
        for(int i = 1; i <= n; ++ i){
        	if(b[i] < 0) ans -= b[i];
        	if(b[i] < 0) add(s, i + n, -b[i]);
        	else add(i + n, t, b[i]);
        }
        cnt = 2 * n + 2;
        tot = 1;
        maxflow = 0;
        // cout << ans << endl;
        dinic();
        if(ans != maxflow || x != y){
        	cout << "No" << endl;
        }else{
        	cout << "Yes" << endl;
        	vector<vector<int>> vis(n + 1, vector<int>(n + 1)); 
        	for(int i = 1; i <= n; ++ i){
        		for(int j = head[i]; j; j = edge[j].next){
        			int v = edge[j].to - n;
        			if(v == s || v == t) continue;
        			// cout << i << " " << v << " " << j << endl;
        			if(edge[j].flow != 0){
        				vis[i][v] = 1;
        			}
        		}
        	}
        	for(int i = 1; i <= n; ++ i){
        		for(int j = 1; j <= n; ++ j) cout << vis[i][j];
        		cout << "\n"; 
        	}
        }
}
int main(){
        ios::sync_with_stdio(false);
        int T = 1;
        // cin >> T; 
        while(T--){
                solve();
        }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3924kb

input:

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

output:

Yes
001
001
111

result:

ok n=3

Test #2:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

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

output:

Yes
110
100
000

result:

ok n=3

Test #3:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

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

output:

No

result:

ok n=3

Test #4:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

1
-
-1
1

output:

No

result:

ok n=1

Test #5:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

1
-
0
0

output:

Yes
0

result:

ok n=1

Test #6:

score: -100
Runtime Error

input:

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

output:

Yes

result: