QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#297394#7857. (-1,1)-Sumpleteucup-team870#WA 1ms8128kbC++203.1kb2024-01-04 13:13:422024-01-04 13:13:42

Judging History

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

  • [2024-01-04 13:13:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8128kb
  • [2024-01-04 13:13:42]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int N = 10010;

struct edge {
    int to, next, flow;
} ed[33000010];

int s, t, deep[N], head[N], cur[N], sz=-1, row[N], col[N];
char a[4040][4040];
bool ksj[4040][4040];

char tmp[N];

void addEdge(int from, int to, int flow) {
    sz++;
    ed[sz].to = to;
    ed[sz].next = head[from];
    ed[sz].flow = flow;
    head[from] = sz;
}

void add(int u, int v, int f) {
    addEdge(u, v, f);
    addEdge(v, u, 0);
}

bool bfs() {
    queue <int> q;
    q.push(s);
    memset(deep, 0, sizeof(deep));
    deep[s] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int i = head[u]; i != -1; i = ed[i].next) {
            int v = ed[i].to;
            if (deep[v] == 0 && ed[i].flow > 0) {
                deep[v] = deep[u] + 1;
                q.push(v);
                if (v == t) return true;
            }
        }
    }
    return false;
}

int dfs(int u, int flow) {
    if (u == t) return flow;
    int rest = flow;
    for (int i = cur[u]; i != -1; i = ed[i].next) {
        int v = ed[i].to;
        if (deep[v] == deep[u] + 1 && ed[i].flow > 0 && rest) {
            int now = dfs(v, min(ed[i].flow, rest));
            if (!now) deep[v] = 0;
            rest -= now;
            ed[i].flow -= now;
            ed[i^1].flow += now;
            if (ed[i].flow) cur[u] = i;
            if (rest == 0) break;
        }
    }
    if (rest == flow) deep[u] = -1;
    return flow - rest;
}

int dinic() {
    int flow = 0;
    while (bfs()) {
        rep (i, 1, t) cur[i] = head[i];
        flow += dfs(s, 1e9);
    }
    return flow;
}

int main() {
    memset(head, -1, sizeof(head));
    int n; scanf("%d", &n);
    rep (i, 1, n) {
        scanf("%s", tmp+1);
        rep (j, 1, n) {
            if (tmp[j] == '+') a[i][j] = 1;
        }
    }
    rep (i, 1, n) {
        scanf("%d", &row[i]);
    }
    rep (i, 1, n) {
        scanf("%d", &col[i]);
    }
    rep (i, 1, n) {
        rep (j, 1, n) {
            if (!a[i][j]) {
                row[i]++, col[j]++;
                ksj[i][j] = 1;
            }
            add(i, j+n, 1);
        }
    }
    s = 2*n+1, t = s+1;
    int sumS = 0;
    rep (i, 1, n) {
        add(s, i, row[i]);
        sumS += row[i];
        add(i+n, t, col[i]);
    }

    int flow = dinic();
    if (flow == sumS) {
        puts("Yes");
        rep (u, 1, n) {
            for (int i = head[u]; i != -1; i = ed[i].next) {
                int v = ed[i].to;
                if (v != s) {
                    if (ed[i].flow == 0) ksj[u][v-n] ^= 1;
                }
            }
        }
        rep (i, 1, n) {
            rep (j, 1, n) {
                printf("%d", ksj[i][j]);
            }
            cout <<'\n';
        }
    } else {
        puts("No");
    }

    return 0;
}

详细

Test #1:

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

input:

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

output:

Yes
111
001
001

result:

ok n=3

Test #2:

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

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: 7740kb

input:

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

output:

No

result:

ok n=3

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 6076kb

input:

1
-
-1
1

output:

Yes
1

result:

wrong answer wrong sum at col 1