結果

問題 No.177 制作進行の宮森あおいです!
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-06 21:20:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 2,674 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 171,044 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 17:01:00
合計ジャッジ時間 2,302 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    struct Edge {
        int from, to, cap, rev;
        Edge() {}
        Edge(int from, int to, int cap, int rev) : from(from), to(to), cap(cap), rev(rev) {}
    };
    int V;
    vector< vector<Edge> > G;
    vector<bool> used;
    void init() {
        G.clear(); G.resize(V);
        used.clear(); used.resize(V);
    }
    void addEdge(int from, int to, int cap) {
        //cout << from << " " << to << " : " << cap << endl;
        G[from].push_back(Edge(from, to, cap, G[to].size()));
        G[to].push_back(Edge(to, from, 0, int(G[from].size()) - 1));
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge& e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int 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 calc(int s, int t) {
        int flow = 0;
        while (true) {
            fill(used.begin(), used.end(), false);
            int f = dfs(s, t, 1e9);
            if (f == 0) return flow;
            flow += f;
        }
    }

    const int INF = 1<<28;

    void solve() {
        int W; cin >> W;
        int N; cin >> N;
        vector<int> J(N); cin >> J;
        int M; cin >> M;
        vector<int> C(M); cin >> C;
        V = 2 + N + M; init();
        for (int i = 0; i < N; i++) addEdge(0, 1 + i, J[i]);
        for (int i = 0; i < M; i++) addEdge(1 + N + i, 1 + N + M, C[i]);
        for (int i = 0; i < M; i++) {
            vector<int> ng(N, false);
            int Q; cin >> Q;
            for (int j = 0; j < Q; j++) {
                int k; cin >> k; k--;
                ng[k] = true;
            }
            for (int j = 0; j < N; j++) {
                if (ng[j]) continue;
                addEdge(1 + j, 1 + N + i, INF);
            }
        }
        cout << (calc(0, 1 + N + M) >= W ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
    }
}

int main() {
    solve();
    return 0;
}

0