結果

問題 No.177 制作進行の宮森あおいです!
ユーザー magstamagsta
提出日時 2021-08-31 12:34:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,975 bytes
コンパイル時間 1,944 ms
コンパイル使用メモリ 180,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-16 17:19:01
合計ジャッジ時間 2,928 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct graph {
    typedef long long flow_type;
    struct edge {
        int u, v;
        flow_type capacity, flow;
        size_t rev;
    };
    int n;
    vector<vector<edge>> adj;
    graph(int n) : n(n), adj(n) { }
    void add_edge(int src, int dst, flow_type capacity) {
        adj[src].push_back({ src, dst, capacity, 0, adj[dst].size() });
        adj[dst].push_back({ dst, src, 0, 0, adj[src].size() - 1 });
    }
    flow_type max_flow(int s, int t) {
        vector<int> level(n), iter(n);
        function<int(void)> levelize = [&]() {
            level.assign(n, -1); level[s] = 0;
            queue<int> Q; Q.push(s);
            while (!Q.empty()) {
                int u = Q.front(); Q.pop();
                if (u == t) break;
                for (auto& e : adj[u]) {
                    if (e.capacity > e.flow && level[e.v] < 0) {
                        Q.push(e.v);
                        level[e.v] = level[u] + 1;
                    }
                }
            }
            return level[t];
        };
        function<flow_type(int, flow_type)> augment = [&](int u, flow_type cur) {
            if (u == t) return cur;
            for (int& i = iter[u]; i < adj[u].size(); ++i) {
                edge& e = adj[u][i], & r = adj[e.v][e.rev];
                if (e.capacity > e.flow && level[u] < level[e.v]) {
                    flow_type f = augment(e.v, min(cur, e.capacity - e.flow));
                    if (f > 0) {
                        e.flow += f;
                        r.flow -= f;
                        return f;
                    }
                }
            }
            return flow_type(0);
        };
        for (int u = 0; u < n; ++u)
            for (auto& e : adj[u]) e.flow = 0;

        flow_type flow = 0;
        while (levelize() >= 0) {
            fill(iter.begin(), iter.end(), 0);
            for (flow_type f; (f = augment(s, 1LL << 60)) > 0; )
                flow += f;
        }
        return flow;
    }
};

int main() {
    int W, N, M; cin >> W >> N;
    vector<int> J(N);
    for (int i = 0; i < N; i++) cin >> J[i];
    cin >> M;
    vector<int> C(M);
    for (int i = 0; i < M; i++) cin >> C[i];
    graph G(2 * N + 2 * M + 2);
    for (int i = 0; i < M; i++) {
        int Q; cin >> Q;
        vector<bool> flag(N, true);
        for (int j = 0; j < Q; j++) {
            int x; cin >> x;
            flag[x - 1] = false;
        }
        for (int j = 0; j < N; j++) {
            if (flag[j]) G.add_edge(N + j, 2 * N + i, W);
        }
    }
    for (int i = 0; i < N; i++) {
        G.add_edge(2 * N + 2 * M, i, W);
        G.add_edge(i, N + i, J[i]);
    }
    for (int i = 0; i < M; i++) {
        G.add_edge(2 * N + M + i, 2 * N + 2 * M + 1, W);
        G.add_edge(2 * N + i, 2 * N + M + i, C[i]);
    }

    if (G.max_flow(2 * N + 2 * M, 2 * N + 2 * M + 1) >= W) cout << "SHIROBAKO" << endl;
    else cout << "BANSAKUTSUKITA" << endl;
}
0