結果

問題 No.177 制作進行の宮森あおいです!
ユーザー maine_honzukimaine_honzuki
提出日時 2020-06-09 22:55:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,579 bytes
コンパイル時間 1,803 ms
コンパイル使用メモリ 178,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-31 01:17:18
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

template <typename T>
class Dinic {
    const T INF;
    struct edge {
        int to;
        T cap;
        int rev;
    };
    vector<vector<edge>> G;
    vector<int> min_cost, iter;
    bool bfs(int s, int t) {
        min_cost.assign(G.size(), -1);
        queue<int> que;
        min_cost[s] = 0;
        que.push(s);
        while (!que.empty() && min_cost[t] == -1) {
            int p = que.front();
            que.pop();
            for (auto& e : G[p]) {
                if (e.cap > 0 && min_cost[e.to] == -1) {
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return min_cost[t] != -1;
    }
    T dfs(int idx, const int t, T flow) {
        if (idx == t)
            return flow;
        for (int& i = iter[idx]; i < (int)G[idx].size(); i++) {
            edge& e = G[idx][i];
            if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
                T d = dfs(e.to, t, min(flow, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    //
public:
    Dinic(int V) : INF(numeric_limits<T>::max() / T{10}), G(V) {}
    void add_edge(int from, int to, T cap) {
        G[from].emplace_back((edge){to, cap, (int)G[to].size()});
        G[to].emplace_back((edge){from, 0, (int)G[from].size() - 1});
    }
    T max_flow(int s, int t) {
        T flow = 0;
        while (bfs(s, t)) {
            iter.assign(G.size(), 0);
            T f = 0;
            while ((f = dfs(s, t, INF)) > 0)
                flow += f;
        }
        return flow;
    }
};

int main() {
    Dinic<int> dinic(300);
    int W, N, M;
    cin >> W;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int J;
        cin >> J;
        dinic.add_edge(250, i, J);
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        int C;
        cin >> C;
        dinic.add_edge(i + 100, 260, C);
    }

    int memo[60][60] = {};
    for (int i = 0; i < M; i++) {
        int Q;
        cin >> Q;
        for (int j = 0; j < Q; j++) {
            int X;
            cin >> X;
            X--;
            memo[X][i] = 1;
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (!memo[i][j])
                dinic.add_edge(i, j + 100, 1e5);
        }
    }

    cout << (dinic.max_flow(250, 260) >= W ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
}
0