結果
問題 |
No.957 植林
|
ユーザー |
|
提出日時 | 2019-12-27 08:37:12 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,199 bytes |
コンパイル時間 | 527 ms |
コンパイル使用メモリ | 47,232 KB |
実行使用メモリ | 22,256 KB |
最終ジャッジ日時 | 2024-10-06 23:58:02 |
合計ジャッジ時間 | 6,297 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 WA * 12 TLE * 1 -- * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:75:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:76:72: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 76 | for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &g[i][j]); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:77:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 77 | for (int i = 1; i <= n; i++) scanf("%d", &r[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:78:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 78 | for (int i = 1; i <= m; i++) scanf("%d", &c[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <vector> #include <queue> using namespace std; #define PB push_back constexpr int kN = int(1E5 + 10), kInf = int(1E9 + 10), kNN = int(3E2 + 10); struct Edge { int to, rev, cap; }; vector<Edge> graph[kN]; int dep[kN], went[kN], iter[kN]; void AddEdge(int u, int v, int c) { graph[u].PB({v, int(graph[v].size()), c}); graph[v].PB({u, int(graph[u].size()) - 1, 0}); return ; } void bfs(int s, int t) { int nxt; queue<int> q; q.push(s); iter[s] = dep[s] = 0; went[s] = t; while (!q.empty()) { nxt = q.front(); q.pop(); for (Edge i : graph[nxt]) if (went[i.to] != t && i.cap > 0) { q.push(i.to); went[i.to] = t; dep[i.to] = dep[nxt] + 1; iter[i.to] = 0; } } return ; } int dfs(int u, int t, int nv) { if (u == t) return nv; int temp; for (int &i = iter[u]; i < int(graph[u].size()); i++) { Edge& nxt = graph[u][i]; if (nxt.cap > 0 && dep[nxt.to] > dep[u]) { temp = dfs(nxt.to, t, min(nv, nxt.cap)); if (temp > 0) { nxt.cap -= temp; graph[nxt.to][nxt.rev].cap += temp; return temp; } } } return 0; } long long int dinic(int s, int t) { long long int ans = 0, f; int cnt = 0; for (int i = 0; i < kN; i++) went[i] = cnt; while (true) { bfs(s, ++cnt); if (went[s] != went[t]) break; while ((f = dfs(s, t, kInf)) > 0) ans += f; } return ans; } int g[kNN][kNN], r[kNN], c[kNN]; int main() { int n, m, s, t, nxt = 1; long long int ans = 0; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf("%d", &g[i][j]); for (int i = 1; i <= n; i++) scanf("%d", &r[i]); for (int i = 1; i <= m; i++) scanf("%d", &c[i]); s = 0; t = n * m + n + m + 1; for (int i = 1; i <= n; i++) ans += r[i]; for (int i = 1; i <= m; i++) ans += c[i]; for (int i = 1; i <= n; i++, nxt++) AddEdge(s, nxt, r[i]); for (int i = 1; i <= m; i++, nxt++) AddEdge(s, nxt, c[i]); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++, nxt++) { AddEdge(nxt, t, g[i][j]); AddEdge(i, nxt, min(r[i], g[i][j])); AddEdge(j + n, nxt, min(c[i], g[i][j])); } printf("%lld\n", ans - dinic(s, t)); }