結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー |
![]() |
提出日時 | 2021-03-05 00:43:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 2,640 bytes |
コンパイル時間 | 4,512 ms |
コンパイル使用メモリ | 265,976 KB |
最終ジャッジ日時 | 2025-01-19 10:18:38 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>#define M_PI 3.14159265358979323846 // piusing 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..destll 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;}