結果
問題 | No.2713 Just Solitaire |
ユーザー | cri |
提出日時 | 2024-07-24 13:08:23 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 4,482 bytes |
コンパイル時間 | 2,793 ms |
コンパイル使用メモリ | 199,768 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-24 13:08:28 |
合計ジャッジ時間 | 3,863 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 4 ms
6,944 KB |
testcase_26 | AC | 4 ms
6,944 KB |
testcase_27 | AC | 4 ms
6,940 KB |
testcase_28 | AC | 3 ms
6,944 KB |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | AC | 3 ms
6,940 KB |
testcase_31 | AC | 3 ms
6,944 KB |
testcase_32 | AC | 3 ms
6,940 KB |
testcase_33 | AC | 3 ms
6,940 KB |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using i128 = __int128_t; #define LINF 9223372036854775807 #define rep(i, x, limit) for (ll i = (ll)x; i < (ll)limit; i++) // Dinic's algorithm for maximum flow // Complexity: O(V^2E) for general graph, O(min(V^(2/3), E^(1/2))E) for unit template <typename flow_t> struct Dinic { const flow_t INF; struct edge { int to; flow_t cap; int rev; bool isrev; int idx; }; vector<vector<edge>> graph; vector<int> min_cost, iter; // V: the number of vertices explicit Dinic(int V) : INF(numeric_limits<flow_t>::max()), graph(V) {} // fromからtoへの容量capの辺をグラフに追加する void add_edge(int from, int to, flow_t cap, int idx = -1) { graph[from].emplace_back( (edge){to, cap, (int)graph[to].size(), false, idx}); graph[to].emplace_back( (edge){from, 0, (int)graph[from].size() - 1, true, idx}); } bool build_augment_path(int s, int t) { min_cost.assign(graph.size(), -1); queue<int> que; min_cost[s] = 0; que.push(s); while (!que.empty() && min_cost[t] == -1) { int p = que.front(); que.pop(); for (auto &e : graph[p]) { if (e.cap > 0 && min_cost[e.to] == -1) { min_cost[e.to] = min_cost[p] + 1; que.push(e.to); } } } return min_cost[t] != -1; } flow_t find_min_dist_augment_path(int idx, const int t, flow_t flow) { if (idx == t) return flow; for (int &i = iter[idx]; i < (int)graph[idx].size(); i++) { edge &e = graph[idx][i]; if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) { flow_t d = find_min_dist_augment_path(e.to, t, min(flow, e.cap)); if (d > 0) { e.cap -= d; graph[e.to][e.rev].cap += d; return d; } } } return 0; } // sからtへの最大流を求め, その値を返す flow_t max_flow(int s, int t) { flow_t flow = 0; while (build_augment_path(s, t)) { iter.assign(graph.size(), 0); flow_t f; while ((f = find_min_dist_augment_path(s, t, INF)) > 0) flow += f; } return flow; } void output() { for (int i = 0; i < graph.size(); i++) { for (auto &e : graph[i]) { if (e.isrev) continue; auto &rev_e = graph[e.to][e.rev]; cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl; } } } vector<bool> min_cut(int s) { vector<bool> used(graph.size()); queue<int> que; que.emplace(s); used[s] = true; while (not que.empty()) { int p = que.front(); que.pop(); for (auto &e : graph[p]) { if (e.cap > 0 and not used[e.to]) { used[e.to] = true; que.emplace(e.to); cout << p << " " << e.to << endl; } } } return used; } }; int main() { ll n, m; cin >> n >> m; vector<ll> a(n), b(m); rep(i, 0, n) cin >> a[i]; rep(i, 0, m) cin >> b[i]; vector<vector<ll>> c(m); rep(i, 0, m) { ll k; cin >> k; rep(j, 0, k) { ll x; cin >> x; x--; c[i].push_back(x); } } Dinic<ll> dinic(n + m + 2); ll s = n + m, t = n + m + 1; ll sum = 0; rep(i, 0, n) { dinic.add_edge(i, t, a[i]); sum += 0; } rep(i, 0, m) { sum -= b[i]; dinic.add_edge(s, i + n, b[i]); for (auto x : c[i]) // ボーナスiの中身 { dinic.add_edge(i + n, x, LINF); } } cout << -(sum + dinic.max_flow(s, t)) << endl; }