結果

問題 No.177 制作進行の宮森あおいです!
ユーザー tubo28tubo28
提出日時 2015-09-24 18:26:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 3,995 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 159,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 14:49:53
合計ジャッジ時間 2,758 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/8;

struct Edge {
    int src, dst;
    int cap;
    Edge(int src_, int dst_, int cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<int> Array;
typedef vector<Array> Matrix;

int dfs(int v, int t, int lim, Matrix &cap, vector<bool> &vis){
    vis[v] = true;
    const size_t n = cap.size();
    if(v == t) return lim;
    for(size_t i = 0; i < n; i++){
        if(vis[i] || cap[v][i] == 0) continue;
        int f = dfs(i, t, min(lim, cap[v][i]), cap, vis);
        if(f > 0){
            cap[v][i] -= f;
            cap[i][v] += f;
            return f;
        }
    }
    return 0;
}

int max_flow(int s, int t, Matrix &cap){
    vector<bool> vis;
    int n = cap.size();
    int maxflow = 0;
    while(1){
        vis.assign(n,false);
        int f = dfs(s,t,inf,cap,vis);
        if(f == 0) break;
        maxflow += f;
    }
    return maxflow;
}

int max_flow(int s, int t, const Graph &g){
    int n = g.size();
    Matrix cap(n, Array(n));
    for(size_t i = 0; i < g.size(); i++){
        for(size_t j = 0; j < g[i].size(); j++){
            cap[g[i][j].src][g[i][j].dst] = g[i][j].cap;
        }
    }
    rep(i,n) dump(cap[i]);
    int res = max_flow(s, t, cap);
    rep(i,n) dump(cap[i]);
    return res;
}

ll W,N;
ll J[60];
ll M;
ll C[60];
bool ok[60][60];

int main(){
    while(cin >> W){
        cin >> N;
        rep(i,N) cin >> J[i];
        cin >> M;
        rep(i,M) cin >> C[i];
        rep(i,N)rep(j,M) ok[i][j] = true;
        rep(i,M){
            int Q; cin >> Q;
            rep(j,Q){
                int X; cin >> X;
                X--;
                ok[X][i] = false;
            }
        }

        int S = N+M, T = N+M+1;
        Graph g(N+M+2);
        rep(i,N){
            g[S].eb(S,i,J[i]);
        }
        rep(i,N)rep(j,M){
            if(ok[i][j]){
                g[i].eb(i,N+j,min(J[i],C[j]));
            }
        }
        rep(i,M){
            g[i+N].eb(i+N,T,C[i]);
        }
        ll f = max_flow(S,T,g);
        dump(f);
        puts(f >= W ? "SHIROBAKO" : "BANSAKUTSUKITA");
    }
}
0