結果

問題 No.177 制作進行の宮森あおいです!
ユーザー planesplanes
提出日時 2022-04-13 12:13:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,197 bytes
コンパイル時間 3,426 ms
コンパイル使用メモリ 178,040 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 22:21:21
合計ジャッジ時間 2,934 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void add_edge(ll, ll, ll)’ 内:
main.cpp:18:41: 警告: narrowing conversion of ‘(& G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)to)))->std::vector<edge>::size()’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘ll’ {aka ‘long long int’} [-Wnarrowing]
   18 |     G[from].push_back({to,cap,G[to].size()});
      |                               ~~~~~~~~~~^~
main.cpp:19:43: 警告: narrowing conversion of ‘((& G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)from)))->std::vector<edge>::size() - 1)’ from ‘std::vector<edge>::size_type’ {aka ‘long unsigned int’} to ‘ll’ {aka ‘long long int’} [-Wnarrowing]
   19 |     G[to].push_back({from,0,G[from].size()-1});
      |                             ~~~~~~~~~~~~~~^~

ソースコード

diff #

#include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)


ll INF=2e18;

struct edge {ll to,cap,rev;};
ll V;
vector<vector<edge>> G;
vector<ll> level;
vector<ll> iter;

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

void bfs(ll s) {
    level=vector<ll> (V,-1);

    queue<ll> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()) {
        ll v=que.front();
        que.pop();
        for(ll i=0;i<G[v].size();i++) {
            edge &e=G[v][i];
            if(e.cap>0&&level[e.to]<0) {
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}


ll dfs(ll v,ll t,ll f) {
    if(v==t) return f;
    for(ll &i=iter[v];i<G[v].size();i++) {
        edge &e=G[v][i];
        if(e.cap>0&&level[v]<level[e.to]) {
            ll 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;
}

ll max_flow(ll s,ll t) {
    ll flow=0;
    for(;;) {
        bfs(s);
        if(level[t]<0) return flow;
       iter=vector<ll> (V,0);
        ll f;
        while((f=dfs(s,t,INF))>0) {
            flow+=f;
        }
    }
}


int main() {
    ll W;cin>>W;
    ll N;cin>>N;
    vector<ll> J(N);
    for(ll i=0;i<N;i++) cin>>J[i];
    ll M;cin>>M;
    vector<ll> C(M);
    for(ll i=0;i<M;i++) cin>>C[i];
    V=N+M+2;
    G=vector<vector<edge>> (V,vector<edge> (0));

    for(ll i=0;i<N;i++) {
        add_edge(0,i+1,J[i]);
    }
    for(ll i=0;i<M;i++){
        add_edge(N+i+1,N+M+1,C[i]);
    }

    for(ll i=0;i<M;i++) {
        ll Q;cin>>Q;
        vector<bool> note(N,false);
        for(ll j=0;j<Q;j++) {
            ll X;cin>>X;
            note[X-1]=true;
        }
        for(ll j=0;j<N;j++) {
            if(note[j]) continue;
            add_edge(j+1,N+i+1,INF);
        }
    }

    ll ans=max_flow(0,N+M+1);
    if(ans>=W) cout<<"SHIROBAKO"<<endl;
    else cout<<"BANSAKUTSUKITA"<<endl;
}



    




    
0