結果
問題 | No.957 植林 |
ユーザー | uwi |
提出日時 | 2019-12-20 20:15:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,668 bytes |
コンパイル時間 | 2,789 ms |
コンパイル使用メモリ | 211,040 KB |
実行使用メモリ | 30,864 KB |
最終ジャッジ日時 | 2023-09-23 03:48:53 |
合計ジャッジ時間 | 28,770 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,604 KB |
testcase_01 | AC | 5 ms
6,548 KB |
testcase_02 | AC | 4 ms
6,560 KB |
testcase_03 | AC | 295 ms
23,000 KB |
testcase_04 | AC | 210 ms
22,852 KB |
testcase_05 | AC | 209 ms
24,408 KB |
testcase_06 | AC | 206 ms
25,020 KB |
testcase_07 | AC | 247 ms
22,448 KB |
testcase_08 | AC | 119 ms
23,160 KB |
testcase_09 | AC | 118 ms
23,380 KB |
testcase_10 | AC | 139 ms
24,024 KB |
testcase_11 | AC | 136 ms
23,796 KB |
testcase_12 | AC | 131 ms
23,244 KB |
testcase_13 | AC | 97 ms
21,428 KB |
testcase_14 | AC | 134 ms
25,076 KB |
testcase_15 | AC | 127 ms
23,560 KB |
testcase_16 | AC | 100 ms
20,628 KB |
testcase_17 | AC | 103 ms
22,104 KB |
testcase_18 | AC | 1,085 ms
22,904 KB |
testcase_19 | AC | 1,172 ms
24,076 KB |
testcase_20 | AC | 1,338 ms
23,764 KB |
testcase_21 | AC | 1,562 ms
24,292 KB |
testcase_22 | AC | 1,602 ms
25,120 KB |
testcase_23 | AC | 1,858 ms
25,844 KB |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 1,987 ms
26,960 KB |
testcase_27 | AC | 1,944 ms
26,812 KB |
testcase_28 | AC | 1,942 ms
26,432 KB |
testcase_29 | AC | 1,898 ms
26,432 KB |
testcase_30 | TLE | - |
testcase_31 | AC | 1,139 ms
22,908 KB |
testcase_32 | AC | 1,274 ms
23,388 KB |
testcase_33 | AC | 1,341 ms
24,644 KB |
testcase_34 | AC | 1,487 ms
24,160 KB |
testcase_35 | AC | 1,456 ms
24,752 KB |
testcase_36 | AC | 1,873 ms
26,264 KB |
testcase_37 | AC | 1,933 ms
25,784 KB |
testcase_38 | TLE | - |
testcase_39 | AC | 1,971 ms
26,716 KB |
testcase_40 | TLE | - |
testcase_41 | AC | 54 ms
25,668 KB |
testcase_42 | AC | 153 ms
25,844 KB |
testcase_43 | AC | 61 ms
25,756 KB |
testcase_44 | AC | 62 ms
26,680 KB |
testcase_45 | AC | 5 ms
6,236 KB |
testcase_46 | AC | 5 ms
6,776 KB |
testcase_47 | AC | 5 ms
6,680 KB |
コンパイルメッセージ
main.cpp: In instantiation of ‘void Dinic<MAXV, T>::addEdge(int, int, T, bool) [with int MAXV = 100000; T = long long int]’: main.cpp:86:13: required from here main.cpp:17:41: 警告: narrowing conversion of ‘((Dinic<100000, long long int>*)this)->Dinic<100000, long long int>::adj[b].std::vector<Dinic<100000, long long int>::edge, std::allocator<Dinic<100000, long long int>::edge> >::size()’ from ‘std::vector<Dinic<100000, long long int>::edge, std::allocator<Dinic<100000, long long int>::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: 警告: narrowing conversion of ‘(((Dinic<100000, long long int>*)this)->Dinic<100000, long long int>::adj[a].std::vector<Dinic<100000, long long int>::edge, std::allocator<Dinic<100000, long long int>::edge> >::size() - 1)’ from ‘std::vector<Dinic<100000, long long int>::edge, std::allocator<Dinic<100000, long long int>::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 << 30) : 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<100000, long long> 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; }