結果

問題 No.177 制作進行の宮森あおいです!
ユーザー face4face4
提出日時 2019-01-30 21:51:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,725 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 80,396 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 07:51:03
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
struct edge{
    int to, cap, rev;
};

#define MAX_V 102
vector<edge> G[MAX_V];
bool used[MAX_V];

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

// v...target vertex, t...end vertex, f...maximum flow 
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;
}

const int INF = 1<<29;

// maxflow from s to t
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0)  return flow;
        flow += f;
    }
}

int main(){
    int w, n, m, c, q, x;
    cin >> w >> n;

    int SINK = 0, DEST = 101;

    vector<int> J(n);
    for(int i = 0; i < n; i++){
        cin >> J[i];
        add_edge(SINK, i+1, J[i]);
    }

    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> c;
        add_edge(51+i, DEST, c);
    }

    for(int i = 0; i < m; i++){
        set<int> no;
        cin >> q;
        while(q-- > 0){
            cin >> x;
            no.insert(x);
        }
        for(int j = 1; j <= n; j++){
            if(no.count(j) == 0)    add_edge(j, 51+i, J[j-1]);
        }
    }

    cout << (max_flow(SINK, DEST) >= w ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;

    return 0;
}
0