結果

問題 No.177 制作進行の宮森あおいです!
ユーザー suzuken_w
提出日時 2020-09-17 20:56:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,903 bytes
コンパイル時間 3,257 ms
コンパイル使用メモリ 223,444 KB
最終ジャッジ日時 2025-01-14 15:41:30
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
const int MAX_V = 3000;
struct Flow{
const ll INF=ll(1e9);
// 
struct edge{
//
ll to,cap,rev;
edge(ll to,ll cap,ll rev):to(to),cap(cap),rev(rev){}
};
//
V<edge> G[MAX_V];//vector""
//DFS調
bool used[MAX_V]={};
//
void add_edge(ll from,ll to,ll cap){
G[from].emplace_back(to,cap,ll(G[to].size()));
G[to].emplace_back(from,0,ll(G[from].size()-1));
}
//DFS
ll dfs(ll v,ll t,ll f){
if(v==t)return f;
used[v]=true;
for(int i=0;i<G[v].size();i++){
edge &e=G[v][i]; //
if(!used[e.to]&&e.cap>0){
ll d=dfs(e.to,t,min<ll>(f,e.cap));
if(d>0){
e.cap-=d;//使
G[e.to][e.rev].cap+=d;//使
return d;
}
}
}
return 0;
}
//st
ll fmax(ll s,ll t){
ll flow=0;
while(1){
for(int i=0;i<MAX_V;i++)used[i]=false;
ll f=dfs(s,t,INF);
if(f==0)return flow;
flow+=f;
}
}
};
int main(){
int w;
cin>>w;
int n;
cin>>n;
V<int> j(n);
for(int i=0;i<n;i++)cin>>j[i];
int m;
cin>>m;
V<int> c(m);
for(int i=0;i<m;i++)cin>>c[i];
Flow flow;
int S=0,T=n+m+2;
for(int i=0;i<n;i++){
flow.add_edge(S,i+1,j[i]);
}
for(int i=0;i<m;i++){
flow.add_edge(i+n+1,T,c[i]);
}
int INF=(1e5);
for(int i=0;i<m;i++){
V<bool> ok(n,true);
int q; cin>>q;
for(int k=0;k<q;k++){
int a;cin>>a;
ok[a-1]=false;
}
for(int k=0;k<n;k++){
if(ok[k]){
flow.add_edge(k+1,i+n+1,INF);
}
}
}
if(w<=flow.fmax(S,T))cout<<"SHIROBAKO"<<"\n";
else cout<<"BANSAKUTSUKITA"<<"\n";
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0