結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー |
![]() |
提出日時 | 2020-12-10 14:24:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 4,638 bytes |
コンパイル時間 | 2,162 ms |
コンパイル使用メモリ | 210,844 KB |
最終ジャッジ日時 | 2025-01-16 21:19:13 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>using namespace std;template<typename T, typename U>using vp = vector<pair<T,U>>;template<typename T>using pque = priority_queue<T>;template<typename T>using lpque = priority_queue<T,vector<T>,greater<T>>;using ll = long long;using pint = pair<int,int>;using pll = pair<ll,ll>;using pil = pair<int,ll>;using pli = pair<ll,int>;using vint = vector<int>;using vll = vector<ll>;using qint = queue<int>;using pqint = pque<int>;using qll = queue<ll>;using pqll = pque<ll>;constexpr double PI = 3.141592653589793;constexpr int INTINF = (1<<30)-1;constexpr ll LLINF = (1LL<<62)-1;constexpr int MPRIME = 1000000007;constexpr int MPRIME9 = 998244353;constexpr ll MMPRIME = (1LL<<61)-1;constexpr char newl = '\n';#define len length()#define pushb push_back#define fi first#define se second#define all(name) name.begin(),name.end()#define rall(name) name.rbegin(),name.rend()#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())template<typename T>struct matrix{private:vector<vector<T>> mat;public:matrix() : matrix(0,0) {}matrix(int h, int w) { resize(h,w); }matrix(int h, int w, T init) { resize(h,w,init); }void resize(int h, int w) {mat=vector<vector<T>>(h,vector<T>(w));}void resize(int h, int w, T init) {mat=vector<vector<T>>(h,vector<T>(w,init));};void in() {for(int i=0; i<mat.size(); i++) for(int j=0; j<mat[i].size(); j++) {cin>>mat[i][j];}}void out() {for(int i=0; i<mat.size(); i++) {int wm=mat[i].size();for(int j=0; j<wm; j++) {cout<<mat[i][j]<<(wm==j+1 ? '\n' : ' ');}}cout<<flush;}inline vector<T> &operator[](int idx) {assert(0<=idx && idx<mat.size());return mat[idx];}};template<class T>inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}template<class T>inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}template<class T>inline void init(T& v) {for(auto &a: v) cin>>a;}template<class T, class U>inline void init(vector<pair<T,U>>& v) {for(auto &a: v) cin>>a.first>>a.second;}template<class T, class N>inline void init(T& v, N n) {v.resize(n);for(auto &a: v) cin>>a;}template<class T, class U, class N>inline void init(vector<pair<T,U>>& v, N n) {v.resize(n);for(auto &a: v) cin>>a.first>>a.second;}template<class T>inline void out(T a) {cout<<a<<endl;}template<class T, class... U>inline void out(T a, U... alist) {cout<<a<<" ";out(forward<U>(alist)...);}template<class N>void resiz(N n) {//empty}template<class N, class T, class... U>void resiz(N n, T&& hd, U&&... tl) {hd.resize(n);resiz(n,forward<U>(tl)...);}long long binpow(long long a, long long ex, long long p=MMPRIME) {long long res = 1;while(ex > 0) {if(ex & 1) (res*=a) %= p;ex>>=1;(a*=a) %= p;}return res;}struct maxflow {private:struct edge {int next;int rev;long long cap;edge(int next, int rev, long long cap) : next(next), rev(rev), cap(cap) {}};const int vnum;vector<vector<edge>> G;vector<bool> used;public:maxflow(int N) : vnum(N), G(N), used(N) {}void add(int from, int to, long long cap) {G[from].push_back(edge(to, G[to].size(), cap));G[to].push_back(edge(from, G[from].size()-1, 0));}private:long long dfs(int s, int t, long long flow) {if(s == t) return flow;used[s] = true;for(edge &ed : G[s]) {if(!used[ed.next] && ed.cap>0) {long long captmp = dfs(ed.next, t, min(flow,ed.cap));if(captmp > 0) {ed.cap -= captmp;G[ed.next][ed.rev].cap += captmp;return captmp;}}}return 0LL;}public:long long solve(int s, int t) {long long res = 0;while(1) {used.assign(vnum, false);long long restmp = dfs(s, t, (1LL<<62)-1);if(restmp == 0) return res;res += restmp;}}};int W,N,M;vector<int> J,C;matrix<bool> X;void input() {cin>>W>>N;J.resize(N);for(int &j: J) cin>>j;cin>>M;C.resize(M);for(int &c: C) cin>>c;X.resize(N,M,true);for(int i=0; i<M; i++) {int Q; cin>>Q;for(int j=0; j<Q; j++) {int x; cin>>x;X[--x][i] = false;}}}void solve() {maxflow mf(N+M+2);for(int i=0; i<N; i++) {mf.add(N+M, i, J[i]);for(int j=0; j<M; j++) {if(X[i][j]) mf.add(i, N+j, (1LL<<62)-1);}}for(int i=0; i<M; i++) mf.add(N+i, N+M+1, C[i]);if(W <= mf.solve(N+M, N+M+1)) cout<<"SHIROBAKO"<<endl;else cout<<"BANSAKUTSUKITA"<<endl;}int main() {cin.tie(nullptr);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(15);int t=1;while(t--) {input();solve();}}