結果

問題 No.177 制作進行の宮森あおいです!
ユーザー pekempeypekempey
提出日時 2015-11-04 23:17:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,304 bytes
コンパイル時間 1,729 ms
コンパイル使用メモリ 158,692 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 13:44:57
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

const int inf = 1e9;

struct MaxFlow {
	struct Edge { int to, cap, rev; };
	vector<int> dist, it;
	vector<vector<Edge>> G;
	MaxFlow(int n) : G(n), dist(n), it(n) {}
	void add(int u, int v, int c) {
		Edge a = {v, c, (int)G[v].size()};
		Edge b = {u, 0, (int)G[u].size()};
		G[u].push_back(a);
		G[v].push_back(b);
	}
	int calc(int s, int t) {
		int res = 0;
		while (bfs(s, t)) {
			fill(it.begin(), it.end(), 0);
			while (int f = dfs(s, t, INT_MAX)) {
				res += f;
			}
		}
		return res;
	}
	bool bfs(int s, int t) {
		fill(dist.begin(), dist.end(), -1);
		queue<int> q;
		q.push(s);
		dist[s] = 0;
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (Edge e : G[v]) {
				if (e.cap > 0 && dist[e.to] < 0) {
					dist[e.to] = dist[v] + 1;
					q.push(e.to);
				}
			}
		}
		return dist[t] >= 0;
	}
	int dfs(int v, int t, int f) {
		if (v == t) return f;
		for (int &i = it[v]; i < G[v].size(); i++) {
			Edge &e = G[v][i];
			if (e.cap > 0 && dist[v] < dist[e.to]) {
				if (int d = dfs(e.to, t, min(f, e.cap))) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
};

int main() {
	int W;
	cin >> W;
	int N;
	cin >> N;
	vector<int> J(N);
	rep (i, N) cin >> J[i];
	int M;
	cin >> M;
	vector<int> C(M);
	rep (i, M) cin >> C[i];
	vector<vector<char>> bad(N, vector<char>(M));
	rep (i, M) {
		int Q;
		cin >> Q;
		rep (j, Q) {
			int X;
			cin >> X;
			X--;
			bad[X][i] = true;
		}
	}

	MaxFlow mf(N + M + 2);
	int src = N + M;
	int dst = src + 1;
	rep (i, N) mf.add(src, i, J[i]);
	rep (i, M) mf.add(i + N, dst, C[i]);
	rep (i, N) rep (j, M) if (!bad[i][j]) {
		mf.add(i, N + j, inf);
	}

	int f = mf.calc(src, dst);
	if (f >= W) {
		cout << "SHIROBAKO" << endl;
	} else {
		cout << "BANSAKUTSUKITA" << endl;
	}
	return 0;
}
0