結果
問題 | No.957 植林 |
ユーザー | uwi |
提出日時 | 2019-12-20 20:19:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,298 ms / 2,000 ms |
コード長 | 2,656 bytes |
コンパイル時間 | 2,559 ms |
コンパイル使用メモリ | 213,316 KB |
実行使用メモリ | 21,016 KB |
最終ジャッジ日時 | 2024-07-16 04:03:17 |
合計ジャッジ時間 | 31,833 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,812 KB |
testcase_01 | AC | 5 ms
6,944 KB |
testcase_02 | AC | 5 ms
6,944 KB |
testcase_03 | AC | 223 ms
18,816 KB |
testcase_04 | AC | 180 ms
17,940 KB |
testcase_05 | AC | 165 ms
19,172 KB |
testcase_06 | AC | 149 ms
19,804 KB |
testcase_07 | AC | 201 ms
18,424 KB |
testcase_08 | AC | 99 ms
18,800 KB |
testcase_09 | AC | 96 ms
19,048 KB |
testcase_10 | AC | 115 ms
19,476 KB |
testcase_11 | AC | 114 ms
18,884 KB |
testcase_12 | AC | 107 ms
18,644 KB |
testcase_13 | AC | 81 ms
16,748 KB |
testcase_14 | AC | 103 ms
19,980 KB |
testcase_15 | AC | 102 ms
18,792 KB |
testcase_16 | AC | 85 ms
16,760 KB |
testcase_17 | AC | 87 ms
18,180 KB |
testcase_18 | AC | 859 ms
18,804 KB |
testcase_19 | AC | 917 ms
18,940 KB |
testcase_20 | AC | 1,002 ms
19,328 KB |
testcase_21 | AC | 1,063 ms
19,716 KB |
testcase_22 | AC | 1,057 ms
19,852 KB |
testcase_23 | AC | 1,217 ms
20,296 KB |
testcase_24 | AC | 1,154 ms
20,496 KB |
testcase_25 | AC | 1,291 ms
20,940 KB |
testcase_26 | AC | 1,213 ms
20,988 KB |
testcase_27 | AC | 1,206 ms
21,016 KB |
testcase_28 | AC | 1,208 ms
20,888 KB |
testcase_29 | AC | 1,191 ms
20,884 KB |
testcase_30 | AC | 1,236 ms
21,016 KB |
testcase_31 | AC | 849 ms
18,764 KB |
testcase_32 | AC | 924 ms
18,932 KB |
testcase_33 | AC | 958 ms
19,328 KB |
testcase_34 | AC | 1,045 ms
19,584 KB |
testcase_35 | AC | 1,027 ms
19,844 KB |
testcase_36 | AC | 1,177 ms
20,240 KB |
testcase_37 | AC | 1,142 ms
20,496 KB |
testcase_38 | AC | 1,298 ms
20,976 KB |
testcase_39 | AC | 1,217 ms
20,884 KB |
testcase_40 | AC | 1,187 ms
20,952 KB |
testcase_41 | AC | 42 ms
20,248 KB |
testcase_42 | AC | 91 ms
20,760 KB |
testcase_43 | AC | 49 ms
20,248 KB |
testcase_44 | AC | 50 ms
20,888 KB |
testcase_45 | AC | 5 ms
6,940 KB |
testcase_46 | AC | 4 ms
6,940 KB |
testcase_47 | AC | 4 ms
6,940 KB |
コンパイルメッセージ
main.cpp: In instantiation of 'void Dinic<MAXV, T>::addEdge(int, int, T, bool) [with int MAXV = 91000; T = int]': main.cpp:86:13: required from here main.cpp:17:41: warning: narrowing conversion of '((Dinic<91000>*)this)->Dinic<91000>::adj[b].std::vector<Dinic<91000>::edge, std::allocator<Dinic<91000>::edge> >::size()' from 'std::vector<Dinic<91000>::edge, std::allocator<Dinic<91000>::edge> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 17 | adj[a].push_back({b, adj[b].size(), cap, 0}); | ~~~~~~~~~~~^~ main.cpp:18:44: warning: narrowing conversion of '(((Dinic<91000>*)this)->Dinic<91000>::adj[a].std::vector<Dinic<91000>::edge, std::allocator<Dinic<91000>::edge> >::size() - 1)' from 'std::vector<Dinic<91000>::edge, std::allocator<Dinic<91000>::edge> >::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 18 | adj[b].push_back({a, adj[a].size() - 1, isDirected ? 0 : cap, 0}); | ~~~~~~~~~~~~~~^~~
ソースコード
#include <bits/stdc++.h> using namespace std; template <int MAXV, class T = int> struct Dinic { const static bool SCALING = true; // non-scaling = V^2E, Scaling=VElog(U) with higher constant int lim = 1; const T INF = numeric_limits<T>::max(); struct edge { int to, rev; T cap, flow; }; int s = MAXV - 2, t = MAXV - 1; int level[MAXV], ptr[MAXV]; vector<edge> adj[MAXV]; void addEdge(int a, int b, T cap, bool isDirected = true) { adj[a].push_back({b, adj[b].size(), cap, 0}); adj[b].push_back({a, adj[a].size() - 1, isDirected ? 0 : cap, 0}); } bool bfs() { queue<int> q({s}); fill_n(level, MAXV, -1); level[s] = 0; while (!q.empty() && level[t] == -1) { int v = q.front(); q.pop(); for (auto e : adj[v]) { if (level[e.to] == -1 && e.flow < e.cap && (!SCALING || e.cap - e.flow >= lim)) { q.push(e.to); level[e.to] = level[v] + 1; } } } return level[t] != -1; } T dfs(int v, T flow) { if (v == t || !flow) return flow; for (; ptr[v] < adj[v].size(); ptr[v]++) { edge &e = adj[v][ptr[v]]; if (level[e.to] != level[v] + 1) continue; if (T pushed = dfs(e.to, min(flow, e.cap - e.flow))) { e.flow += pushed; adj[e.to][e.rev].flow -= pushed; return pushed; } } return 0; } long long calc() { long long flow = 0; for (lim = SCALING ? (1 << 29) : 1; lim > 0; lim >>= 1) { while (bfs()) { fill_n(ptr, MAXV, 0); while (T pushed = dfs(s, INF)) flow += pushed; } } return flow; } }; int n, m; int G[305][305]; int R[305]; int C[305]; Dinic<91000> D; int main() { scanf("%d %d", &n, &m); for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ scanf("%d", &G[i][j]); } } for(int i = 0;i < n;i++){ scanf("%d", &R[i]); } for(int i = 0;i < m;i++){ scanf("%d", &C[i]); } for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ D.addEdge(i*m+j, D.t, G[i][j]); } } long long ans = 0; for(int i = 0;i < n;i++){ D.addEdge(D.s, n*m+i, R[i]); ans += R[i]; for(int j = 0;j < m;j++){ D.addEdge(n*m+i, i*m+j, R[i]); } } for(int i = 0;i < m;i++){ D.addEdge(D.s, n*m+n+i, C[i]); ans += C[i]; for(int j = 0;j < n;j++){ D.addEdge(n*m+n+i, j*m+i, C[i]); } } ans -= D.calc(); cout << ans << endl; return 0; }