結果

問題 No.177 制作進行の宮森あおいです!
ユーザー niiminiimi
提出日時 2018-09-09 22:09:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,774 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 149,988 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 21:07:33
合計ジャッジ時間 2,244 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

typedef struct{
	int to, cap, rev;
}edge;

vector<edge> G[20002];
bool used[20002];

void add_edge(int from, int to, int cap){
	int p = G[to].size(), q = G[from].size();
	G[from].pb((edge){to, cap, p});
	G[to].pb((edge){from, 0, q});
}

int dfs(int v, int t, int 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){
			int 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;
}

int max_flow(int s, int t){
	int flow = 0;
	while(1){
		Rep(i, sizeof(used)/sizeof(*used)){
			used[i] = false;
		}
		int f = dfs(s, t, inf);
		if(f == 0) return flow;
		flow += f;
	}
}

int main(){
	int w; cin >> w;
	int n; cin >> n; int a[n];
	Rep(i, n){ cin >> a[i]; }
	int m; cin >> m; int b[m];
	Rep(i, m){ cin >> b[i]; }
	vector<int> v[m];
	Rep(i, m){
		int q; cin >> q;
		Rep(j, q){
			int p; cin >> p;
			v[i].pb(p-1);
		}
	}
	int s = 20000, t = 20001;
	Rep(i, n){
		add_edge(s, i, a[i]);
	}
	Rep(i, m){
		add_edge(i+10000, t, b[i]);
	}
	Rep(i, n){
		Rep(j, m){
			bool flag = true;
			Rep(k, v[j].size()){
				if(i == v[j][k]){
					flag = false;
				}
			}
			if(flag){
				add_edge(i, j+10000, inf);
			}
		}
	}
	int f = max_flow(s, t);
	if(f >= w){
		cout << "SHIROBAKO" << endl;
	}else{
		cout << "BANSAKUTSUKITA" << endl;
	}
	return 0;
}
0