結果
問題 | No.2713 Just Solitaire |
ユーザー |
|
提出日時 | 2024-07-24 13:07:07 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,482 bytes |
コンパイル時間 | 2,415 ms |
コンパイル使用メモリ | 198,352 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-24 13:07:14 |
合計ジャッジ時間 | 5,843 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 3 ms
6,944 KB |
testcase_07 | RE | - |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 4 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | RE | - |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | AC | 4 ms
6,944 KB |
testcase_26 | AC | 3 ms
6,944 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | AC | 4 ms
6,944 KB |
testcase_31 | AC | 4 ms
6,940 KB |
testcase_32 | AC | 4 ms
6,944 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(n); 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; }