結果

問題 No.177 制作進行の宮森あおいです!
ユーザー Taiki0715Taiki0715
提出日時 2023-09-17 16:57:50
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 5,095 bytes
コンパイル時間 6,994 ms
コンパイル使用メモリ 153,984 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 16:58:15
合計ジャッジ時間 6,553 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcount(x)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
  if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
  else return init;
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
void SOLVE();
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef LOCAL
  clock_t start=clock();
  #endif
  int testcase=1;
  //cin>>testcase;
  for(int i=0;i<testcase;i++){
    SOLVE();
  }
  #ifdef LOCAL
  cout<<"time:";
  cout<<(clock()-start)/1000;
  cout<<"ms\n";
  #endif
}
template<typename T>
struct Dinic{
private:
  struct edge{
    int to,rev;
    T cap;
  };
  int n;
  vector<vector<edge>>g;
  vector<pair<int,int>>pos;
  template<typename T2>
  struct Q{
    vector<T2>data;
    int p;
    Q():p(0){}
    void push(T2 x){
      data.push_back(x);
    }
    int front()const{
      return data[p];
    }
    void pop(){p++;}
    void clear(){
      data.clear();
      p=0;
    }
    bool empty()const{
      return p==data.size();
    }
  };
public:
  Dinic():n(0){}
  Dinic(int n):n(n),g(n){}
  void add_edge(int u,int v,T cap){
    pos.push_back({u,g[u].size()});
    int f=g[u].size();
    int t=g[v].size();
    if(u==v)t++;
    g[u].push_back({v,t,cap});
    g[v].push_back({u,f,0});
  }
  struct E{
    int from,to;
    T cap,flow;
  };
  vector<E>edges()const{
    int m=pos.size();
    vector<E>ret(m);
    rep(i,m){
      edge e=g[pos[i].first][pos[i].second];
      edge r=g[e.to][e.rev];
      ret[i]={pos[i].first,e.to,e.cap+r.cap,r.cap};
    }
    return ret;
  }
  T flow(int s,int t,T limit){
    assert(0<=s&&s<n);
    assert(0<=t&&t<n);
    assert(s!=t);
    vector<int>level(n),iter(n);
    Q<int>que;
    auto bfs=[&](){
      fill(all(level),-1);
      level[s]=0;
      que.clear();
      que.push(s);
      while(!que.empty()){
        int x=que.front();
        que.pop();
        for(auto e:g[x]){
          if(e.cap==0||level[e.to]>=0)continue;
          level[e.to]=level[x]+1;
          if(e.to==t)return;
          que.push(e.to);
        }
      }
    };
    function<T(int,T)>dfs=[&](int v,T up)->T {
      if(v==s)return up;
      T ret=0;
      int lv=level[v];
      reps(i,iter[v],g[v].size()){
        edge e=g[v][i];
        if(lv<=level[e.to]||g[e.to][e.rev].cap==0)continue;
        T d=dfs(e.to,min(up-ret,g[e.to][e.rev].cap));
        if(d<=0)continue;
        g[v][i].cap+=d;
        g[e.to][e.rev].cap-=d;
        ret+=d;
        if(ret==up)return ret;
      }
      level[v]=n;
      return ret;
    };
    T flow=0;
    while(flow<limit){
      bfs();
      if(level[t]==-1)break;
      fill(all(iter),0);
      T f=dfs(t,limit-flow);
      if(!f)break;
      flow+=f;
    }
    return flow;
  }
  T flow(int s,int t){
    return flow(s,t,numeric_limits<T>::max());
  }
  vector<bool>min_cut(int s){
    vector<bool>ret(n,false);
    Q<int>que;
    que.push(s);
    while(!que.empty()){
      int x=que.front();
      que.pop();
      ret[x]=true;
      for(auto e:g[x]){
        if(e.cap&&!ret[e.to]){
          ret[e.to]=true;
          que.push(e.to);
        }
      }
    }
    return ret;
  }
};
void SOLVE(){
  int w,n;
  cin>>w>>n;
  vector<int>a(n);
  cin>>a;
  int m;
  cin>>m;
  vector<int>b(m);
  cin>>b;
  Dinic<int>g(n+m+2);
  int s=n+m,t=s+1;
  rep(i,n)g.add_edge(s,i,a[i]);
  rep(j,m)g.add_edge(j+n,t,b[j]);
  rep(i,m){
    int q;
    cin>>q;
    vector<bool>ok(n,true);
    while(q--){
      int x;
      cin>>x;
      x--;
      ok[x]=false;
    }
    rep(j,n)if(ok[j])g.add_edge(j,i+n,1e9);
  }
  cout<<(g.flow(s,t)>=w?"SHIROBAKO":"BANSAKUTSUKITA")<<endl;
}
0