結果

問題 No.177 制作進行の宮森あおいです!
ユーザー ctyl_0ctyl_0
提出日時 2015-11-30 03:58:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,372 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 99,272 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 05:56:53
合計ジャッジ時間 1,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define nil -1
typedef long long ll;

using namespace std;

inline int input(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template
// goal, capacity, index of reverse edge
struct edge {
    int to, cap, rev;
};

// O(EV^2)
class Dinic{
public:
    int V;
    vector<vector<edge>> G;
    vector<int> L;
    vector<int> I;
    
    Dinic(int v){
        G.resize(v), L.resize(v), I.resize(v);
        V = v;
    }
    
    // add edge
    void add(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});
    }
    
    // label dist from s
    void bfs(int s){
        L.assign(V, -1);
        queue<int> q;
        L[s] = 0;
        q.push(s);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            rep(i, G[v].size()){
                edge &e = G[v][i];
                if (e.cap > 0 && L[e.to] < 0) {
                    L[e.to] = L[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    
    // search positive path
    int dfs(int v, int t, int f){
        if (v == t) return f;
        for (int &i = I[v]; i < G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && L[v] < L[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    // calc max flow
    int max_flow(int s, int t){
        int flow = 0;
        for (;;) {
            bfs(s);
            if (L[t] < 0) return flow;
            I.assign(V, 0);
            int f;
            while ((f = dfs(s, t, inf)) > 0) {
                flow += f;
            }
        }
    }
};

int main() {
    cin.tie(0);
    // source code
    int W = input(); // カットの数
    int N = input(); // 原画マンの数
    vector<int> J(N); // 原画マンが描けるカットの数
    rep(i, N){
        J[i] = input();
    }
    int M = input(); // 作画監督の数
    vector<int> C(M); // 作画監督が仕上げられるカットの数
    rep(i, M){
        C[i] = input();
    }
    
    Dinic D(N + M + 2);
    
    rep(i, N){
        D.add(0, i + 1, J[i]);
    }
    rep(i, M){
        D.add(N + i + 1, N + M + 1, C[i]);
    }
    
    rep(i, M){
        int Q = input();
        vector<int> X(N, 1);
        rep(j, Q){
            X[input() - 1] = 0;
        }
        rep(j, N){
            if (X[j]) D.add(j + 1, N + i + 1, J[j]);
        }
    }
    
    int ret = D.max_flow(0, N + M + 1);
    
    if (ret >= W) {
        output("SHIROBAKO", 0);
    }
    else{
        output("BANSAKUTSUKITA", 0);
    }
    
    return 0;
}
0