結果

問題 No.177 制作進行の宮森あおいです!
ユーザー tottoripapertottoripaper
提出日時 2015-07-19 18:47:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 67,592 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 19:18:48
合計ジャッジ時間 1,250 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 8 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,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Ford-Fulkerson法

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <tuple>

typedef std::tuple<int,int,int> P;

int W, N, M;
int J[51], C[51];
// [0, N): 原画
// [N, N+M): 作画監督
// N+M: 始点
// N+M+1: 終点
std::vector<P> G[200];
bool visited[200];
int INF = 1001001001;

void addEdge(int from, int to, int cap){
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size()-1);
}

int dfs(int v, int f){
    if(v == N+M+1){return f;}
    
    visited[v] = true;

    for(auto &e : G[v]){
        int to, cap, rev;
        std::tie(to, cap, rev) = e;
        
        if(visited[to]){continue;}
        if(cap == 0){continue;}

        int res = dfs(to, std::min(f, cap));
        if(res == 0){continue;}
        
        std::get<1>(e) -= res;
        std::get<1>(G[to][rev]) += res;

        return res;
    }

    return 0;
}

int maxFlow(){
    int f = 0;
    while(1){
        memset(visited, 0, sizeof(visited));
        int x = dfs(N+M, INF);
        if(x == 0){return f;}
        f += x;
    }
}

int main(){
    scanf("%d", &W);
    scanf("%d", &N);
    for(int i=0;i<N;i++){
        scanf("%d", J+i);
    }
    scanf("%d", &M);
    for(int i=0;i<M;i++){
        scanf("%d", C+i);
    }

    for(int i=0;i<M;i++){
        addEdge(i+N, N+M+1, C[i]);
    }

    for(int i=0;i<N;i++){
        addEdge(N+M, i, J[i]);
    }
    
    for(int i=0;i<M;i++){
        int q;
        scanf("%d", &q);

        bool flags[51];
        std::fill(flags, flags+51, false);
        
        for(int j=0;j<q;j++){
            int x;
            scanf("%d", &x);
            x -= 1;

            flags[x] = true;
        }

        for(int j=0;j<N;j++){
            if(flags[j]){continue;}

            addEdge(j, i+N, J[j]);
        }
    }

    // printf("%d\n", maxFlow());
    if(maxFlow() >= W){puts("SHIROBAKO");}
    else{puts("BANSAKUTSUKITA");}
}
0