結果
問題 | No.957 植林 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-19 22:14:14 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,663 ms / 2,000 ms |
コード長 | 3,295 bytes |
コンパイル時間 | 984 ms |
コンパイル使用メモリ | 104,128 KB |
実行使用メモリ | 23,392 KB |
最終ジャッジ日時 | 2023-09-21 07:30:20 |
合計ジャッジ時間 | 37,095 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
13,796 KB |
testcase_01 | AC | 4 ms
13,716 KB |
testcase_02 | AC | 3 ms
13,712 KB |
testcase_03 | AC | 105 ms
22,856 KB |
testcase_04 | AC | 83 ms
23,012 KB |
testcase_05 | AC | 76 ms
23,200 KB |
testcase_06 | AC | 88 ms
23,000 KB |
testcase_07 | AC | 110 ms
22,952 KB |
testcase_08 | AC | 47 ms
22,936 KB |
testcase_09 | AC | 48 ms
22,952 KB |
testcase_10 | AC | 43 ms
22,940 KB |
testcase_11 | AC | 42 ms
22,952 KB |
testcase_12 | AC | 43 ms
23,020 KB |
testcase_13 | AC | 31 ms
22,788 KB |
testcase_14 | AC | 39 ms
22,976 KB |
testcase_15 | AC | 35 ms
23,144 KB |
testcase_16 | AC | 31 ms
22,788 KB |
testcase_17 | AC | 32 ms
22,884 KB |
testcase_18 | AC | 1,169 ms
22,900 KB |
testcase_19 | AC | 1,205 ms
22,900 KB |
testcase_20 | AC | 1,263 ms
22,980 KB |
testcase_21 | AC | 1,347 ms
23,016 KB |
testcase_22 | AC | 1,414 ms
23,208 KB |
testcase_23 | AC | 1,466 ms
23,232 KB |
testcase_24 | AC | 1,521 ms
23,372 KB |
testcase_25 | AC | 1,595 ms
23,148 KB |
testcase_26 | AC | 1,618 ms
23,132 KB |
testcase_27 | AC | 1,605 ms
23,128 KB |
testcase_28 | AC | 1,614 ms
23,176 KB |
testcase_29 | AC | 1,605 ms
23,056 KB |
testcase_30 | AC | 1,663 ms
23,212 KB |
testcase_31 | AC | 1,178 ms
23,032 KB |
testcase_32 | AC | 1,205 ms
22,988 KB |
testcase_33 | AC | 1,250 ms
22,996 KB |
testcase_34 | AC | 1,321 ms
22,968 KB |
testcase_35 | AC | 1,404 ms
23,060 KB |
testcase_36 | AC | 1,450 ms
23,324 KB |
testcase_37 | AC | 1,528 ms
23,268 KB |
testcase_38 | AC | 1,596 ms
23,392 KB |
testcase_39 | AC | 1,570 ms
23,376 KB |
testcase_40 | AC | 1,582 ms
23,288 KB |
testcase_41 | AC | 13 ms
22,712 KB |
testcase_42 | AC | 17 ms
23,364 KB |
testcase_43 | AC | 20 ms
22,696 KB |
testcase_44 | AC | 26 ms
23,280 KB |
testcase_45 | AC | 4 ms
13,764 KB |
testcase_46 | AC | 4 ms
14,000 KB |
testcase_47 | AC | 4 ms
13,832 KB |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } namespace MF { const int LIM_N = 500010; const int LIM_M = 500010; using wint = Int; const wint wEPS = 0; const wint wINF = 1001001001001001001LL; int n, m, ptr[LIM_N], nxt[LIM_M * 2], zu[LIM_M * 2]; wint capa[LIM_M * 2], tof; int lev[LIM_N], see[LIM_N], que[LIM_N], *qb, *qe; void init(int _n) { n = _n; m = 0; fill(ptr, ptr + n, -1); } void ae(int u, int v, wint w0, wint w1 = 0) { nxt[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w0; ++m; nxt[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = w1; ++m; } wint augment(int src, int ink, wint flo) { if (src == ink) return flo; for (int &i = see[src]; ~i; i = nxt[i]) if (capa[i] > wEPS && lev[src] < lev[zu[i]]) { const wint f = augment(zu[i], ink, min(flo, capa[i])); if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; } } return 0; } bool solve(int src, int ink, wint flo = wINF) { for (tof = 0; tof + wEPS < flo; ) { qb = qe = que; fill(lev, lev + n, -1); for (lev[*qe++ = src] = 0, see[src] = ptr[src]; qb != qe; ) { const int u = *qb++; for (int i = ptr[u]; ~i; i = nxt[i]) if (capa[i] > wEPS) { const int v = zu[i]; if (lev[v] == -1) { lev[*qe++ = v] = lev[u] + 1; see[v] = ptr[v]; if (v == ink) goto au; } } } return false; au: for (wint f; (f = augment(src, ink, flo - tof)) > wEPS; tof += f); } return true; } } int main() { int H, W; for (; ~scanf("%d%d", &H, &W); ) { vector<vector<Int>> G(H, vector<Int>(W)); for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) { scanf("%lld", &G[x][y]); } vector<Int> R(H); for (int x = 0; x < H; ++x) { scanf("%lld", &R[x]); } vector<Int> C(W); for (int y = 0; y < W; ++y) { scanf("%lld", &C[y]); } MF::init(2 + H + W + H * W); for (int x = 0; x < H; ++x) { MF::ae(0, 2 + x, R[x]); } for (int y = 0; y < W; ++y) { MF::ae(0, 2 + H + y, C[y]); } for (int x = 0; x < H; ++x) for (int y = 0; y < W; ++y) { const int v = 2 + H + W + x * W + y; MF::ae(2 + x, v, MF::wINF); MF::ae(2 + H + y, v, MF::wINF); MF::ae(v, 1, G[x][y]); } MF::solve(0, 1); Int ans = 0; for (int x = 0; x < H; ++x) { ans += R[x]; } for (int y = 0; y < W; ++y) { ans += C[y]; } ans -= MF::tof; printf("%lld\n", ans); } return 0; }