QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624695#5114. Cells Coloringm107239#WA 12ms4064kbC++203.7kb2024-10-09 16:26:422024-10-09 16:26:44

Judging History

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

  • [2024-10-09 16:26:44]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:4064kb
  • [2024-10-09 16:26:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;

template<class T>
struct MaxFlow {
    struct _Edge {
        int to;
        T cap;
        _Edge(int to, T cap) : to(to), cap(cap) {}
    };
     
    int n;
    std::vector<_Edge> e;
    std::vector<std::vector<int>> g;
    std::vector<int> cur, h;
     
    MaxFlow() {}
    MaxFlow(int n) {
        init(n);
    }
     
    void init(int n) {
        this->n = n;
        e.clear();
        g.assign(n, {});
        cur.resize(n);
        h.resize(n);
    }
     
    bool bfs(int s, int t) {
        h.assign(n, -1);
        std::queue<int> que;
        h[s] = 0;
        que.push(s);
        while (!que.empty()) {
            const int u = que.front();
            que.pop();
            for (int i : g[u]) {
                auto [v, c] = e[i];
                if (c > 0 && h[v] == -1) {
                    h[v] = h[u] + 1;
                    if (v == t) {
                        return true;
                    }
                    que.push(v);
                }
            }
        }
        return false;
    }
     
    T dfs(int u, int t, T f) {
        if (u == t) {
            return f;
        }
        auto r = f;
        for (int &i = cur[u]; i < int(g[u].size()); ++i) {
            const int j = g[u][i];
            auto [v, c] = e[j];
            if (c > 0 && h[v] == h[u] + 1) {
                auto a = dfs(v, t, std::min(r, c));
                e[j].cap -= a;
                e[j ^ 1].cap += a;
                r -= a;
                if (r == 0) {
                    return f;
                }
            }
        }
        return f - r;
    }
    void addEdge(int u, int v, T c) {
        g[u].push_back(e.size());
        e.emplace_back(v, c);
        g[v].push_back(e.size());
        e.emplace_back(u, 0);
    }
    T flow(int s, int t) {
        T ans = 0;
        while (bfs(s, t)) {
            cur.assign(n, 0);
            ans += dfs(s, t, std::numeric_limits<T>::max());
        }
        return ans;
    }
     
    std::vector<bool> minCut() {
        std::vector<bool> c(n);
        for (int i = 0; i < n; i++) {
            c[i] = (h[i] != -1);
        }
        return c;
    }
     
    struct Edge {
        int from;
        int to;
        T cap;
        T flow;
    };
    std::vector<Edge> edges() {
        std::vector<Edge> a;
        for (int i = 0; i < e.size(); i += 2) {
            Edge x;
            x.from = e[i + 1].to;
            x.to = e[i].to;
            x.cap = e[i].cap + e[i + 1].cap;
            x.flow = e[i + 1].cap;
            a.push_back(x);
        }
        return a;
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    int c, d;
    cin >> c >> d;

    MaxFlow<int> g(n + m + 2);
    int S = n + m, T = S + 1;
    vector<string> s(n);
    int id = n + m, cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        for (auto c : s[i]) {
            cnt += (c == '.');
        }
        g.addEdge(S, i, 0);
    }
    for (int i = 0; i < m; i++) {
        int v = 0;
        for (int j = 0; j < n; j++) {
            if (s[j][i] == '.') {
                v++;
                g.addEdge(j, i + n, 1);
            }
        }
        g.addEdge(i + n, T, v);
    }

    ll ans = 1LL * d * cnt;
    int f = 0;
    for (int i = 1; i <= max(n, m); i++) {
        for (int i : g.g[S]) {
            g.e[i].cap++;
        }
        f += g.flow(S, T);
        ans = min(ans, 1LL * c * i + 1LL * d * (cnt - f));
    }
    cout << ans << endl;
    return 0;
}

詳細信息

Test #1:

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

input:

3 4 2 1
.***
*..*
**..

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 4 1 2
.***
*..*
**..

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 12ms
memory: 4064kb

input:

250 250 965680874 9042302
..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.***
....**.*******.*.******...

output:

109628492572

result:

wrong answer 1st numbers differ - expected: '109972100048', found: '109628492572'