結果

問題 No.177 制作進行の宮森あおいです!
ユーザー ks115ks115
提出日時 2021-07-14 23:41:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,437 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 212,508 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 02:12:32
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

using flow_t = int;

struct Edge {
    int to, rev;
    flow_t cap;    
};

class Dinic {
   public:
    Dinic(int v) : N(v), INF(numeric_limits<flow_t>::max()), G(v) {}

    void add(int from, int to, flow_t cap) {
        G[from].push_back({to, (int)G[to].size(), cap});
        G[to].push_back({from, (int)G[from].size() - 1, 0});
    }

    flow_t max_flow(int s, int t) {
        flow_t flow = 0;
        while (bfs(s, t)) {
            iter.assign(N, 0);
            flow_t f = 0;
            while ((f = dfs(s, t, INF)) > 0) flow += f; 
        }
        return flow;
    }

   private:
    int N;
    const flow_t INF;
    vector<vector<Edge>> G;
    vector<int> level, iter;

    bool bfs(int s, int t) {
        level.assign(N, -1);
        level[s] = 0;

        queue<int> q;
        q.push(s);
        while (!q.empty() && level[t] == -1) {
            auto v = q.front(); q.pop();
            for (auto &e : G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
        return level[t] != -1;
    }

    flow_t dfs(int v, const int t, flow_t f) {
        if (v == t) return f;
        for (int &i = iter[v]; i < (int)G[v].size(); i++) {
            auto &e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                auto d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

int main() {
    int W, N; cin >> W >> N;
    vector<int> J(N);
    for (auto &j : J) cin >> j;
    int M; cin >> M;
    vector<int> C(M);
    for (auto &c : C) cin >> c;

    Dinic mf(N + M + 2);
    REP(i, 0, M) {
        int Q; cin >> Q;
        vector<bool> ok(N, true);
        REP(j, 0, Q) {
            int x; cin >> x;
            ok[--x] = false;
        }
        REP(j, 0, N) if (ok[j]) mf.add(j, N + i, W);
    }

    REP(i, 0, N) mf.add(N + M, i, J[i]);
    REP(i, 0, M) mf.add(N + i, N + M + 1, C[i]);

    cout << ((mf.max_flow(N + M, N + M + 1) >= W) ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl; 

    return 0;
}
0