結果

問題 No.177 制作進行の宮森あおいです!
ユーザー nanophoto12nanophoto12
提出日時 2021-03-05 00:43:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,640 bytes
コンパイル時間 4,994 ms
コンパイル使用メモリ 268,772 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 15:52:26
合計ジャッジ時間 5,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

template<typename T>
void chmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void chmaxmap(map<T, T>& m, T key, T value) {
	if (m.count(key)) {
		chmax(m[key], value);
	}
	else {
		m[key] = value;
	}
}

template<typename T>
void chmin(T& reference, T value) {
	reference = min(reference, value);
}


#include <atcoder/all>
using namespace atcoder;

struct MaxFlowCalculator {
	typedef ll flow_type;
	//g.first...cost
	//g.second..dest
	ll max_flow(int s, int t, const vector<vector<pair<flow_type, flow_type>>>& g) {
		struct edge_ { flow_type to, cap, rev; };
		vector<bool> used(g.size(), false);
		vector<vector<edge_>> G(g.size());
		for (int i = 0; i < g.size(); i++) for (int j = 0; j < g[i].size(); j++)
		{
			flow_type from = i, to = g[i][j].second;
			flow_type cap = g[i][j].first;
			G[from].push_back({ to, cap, (flow_type)G[to].size() });
			G[to].push_back({ from, 0, (flow_type)G[from].size() - 1 });
		}
		auto dfs = [&](auto&& f, flow_type v, flow_type t, flow_type fl)->int {
			if (v == t) return fl;
			used[v] = true;
			rep(i, G[v].size()) {
				edge_& e = G[v][i];
				if (!used[e.to] && e.cap > 0) {
					flow_type d = f(f, e.to, t, min(fl, e.cap));
					if (d > 0) {
						e.cap -= d;
						G[e.to][e.rev].cap += d;
						return d;
					}
				}
			}
			return 0LL;
		};
		flow_type flow = 0;
		while (1) {
			used.assign(used.size(), false);
			flow_type f = dfs(dfs, s, t, 1e18);
			if (f == 0) return flow;
			flow += f;
		}
	}
};


int main() {
	int w, n, m;
	cin >> w >> n;
	vector<ll> js(n);
	rep(i, n) cin >> js[i];
	cin >> m;
	vector<ll> cs(m);
	rep(i, m) cin >> cs[i];
	vector<vector<bool>> qs(m, vector<bool>(n, true));
	rep(i, m) {
		int q;
		cin >> q;
		rep(j, q) {
			int t;
			cin >> t; t--;
			qs[i][t] = false;
		}
	}
	vector<vector<P>> graph(n + m + 2);
	int start = n + m;
	rep(i, n) {
		graph[start].emplace_back(js[i], i);
	}
	rep(i, n) {
		rep(j, m) {
			if (qs[j][i]) {
				graph[i].emplace_back(1e15, n + j);
			}
		}
	}
	int goal = start + 1;
	rep(j, m) {
		graph[n + j].emplace_back(cs[j], goal);
	}
	MaxFlowCalculator f;
	ll ans = f.max_flow(start, goal, graph);
	if (ans >= w) {
		cout << "SHIROBAKO" << endl;
	}
	else{
		cout << "BANSAKUTSUKITA" << endl;
	}	
	return 0;
}

0