結果
問題 | No.957 植林 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-19 22:07:38 |
言語 | D (dmd 2.106.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,608 bytes |
コンパイル時間 | 915 ms |
コンパイル使用メモリ | 122,840 KB |
実行使用メモリ | 44,936 KB |
最終ジャッジ日時 | 2024-06-22 03:53:40 |
合計ジャッジ時間 | 8,806 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
13,760 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 312 ms
24,384 KB |
testcase_04 | AC | 260 ms
25,736 KB |
testcase_05 | AC | 287 ms
27,816 KB |
testcase_06 | AC | 309 ms
30,888 KB |
testcase_07 | AC | 319 ms
26,928 KB |
testcase_08 | AC | 196 ms
34,664 KB |
testcase_09 | AC | 194 ms
31,312 KB |
testcase_10 | AC | 228 ms
30,368 KB |
testcase_11 | AC | 221 ms
30,500 KB |
testcase_12 | AC | 233 ms
29,024 KB |
testcase_13 | AC | 160 ms
21,232 KB |
testcase_14 | AC | 206 ms
31,372 KB |
testcase_15 | AC | 184 ms
28,304 KB |
testcase_16 | AC | 160 ms
18,840 KB |
testcase_17 | AC | 160 ms
23,416 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } class MaxFlow(Capa) { enum Capa wEPS = 0; enum Capa wINF = 10L^^18; int n, m; int[][] g; int[] zu; Capa[] capa; Capa tof; int[] lev, see, que; this(int n) { this.n = n; m = 0; g = new int[][n]; zu = []; capa = []; lev = new int[n]; see = new int[n]; que = new int[n]; } void addEdge(int u, int v, Capa w0, Capa w1 = 0) { g[u] ~= m; zu ~= v; capa ~= w0; ++m; g[v] ~= m; zu ~= u; capa ~= w1; ++m; } Capa augment(int src, int ink, Capa flo) { if (src == ink) return flo; foreach (i; g[src][see[src] .. $]) { if (capa[i] > wEPS && lev[src] < lev[zu[i]]) { Capa f = augment(zu[i], ink, min(flo, capa[i])); if (f > wEPS) { capa[i] -= f; capa[i ^ 1] += f; return f; } } ++see[src]; } return 0; } bool dinic(int src, int ink, Capa flo = wINF) { for (tof = 0; tof + wEPS < flo; ) { int[] q; lev[] = -1; dinicBFS: for (lev[src] = 0, q ~= src; !q.empty; ) { int u = q.front; q.popFront; foreach (i; g[u]) { int v = zu[i]; if (capa[i] > wEPS && lev[v] == -1) { lev[v] = lev[u] + 1; q ~= v; if (v == ink) break dinicBFS; } } } if (lev[ink] == -1) return false; see[] = 0; for (; ; ) { Capa f = augment(src, ink, flo - tof); if (f <= wEPS) break; tof += f; } } return true; } } void main() { try { for (; ; ) { const H = readInt(); const W = readInt(); auto G = new long[][](H, W); foreach (x; 0 .. H) foreach (y; 0 .. W) { G[x][y] = readLong(); } auto R = new long[H]; foreach (x; 0 .. H) { R[x] = readLong(); } auto C = new long[W]; foreach (y; 0 .. W) { C[y] = readLong(); } auto mf = new MaxFlow!long(2 + H + W + H * W); foreach (x; 0 .. H) { mf.addEdge(0, 2 + x, R[x]); } foreach (y; 0 .. W) { mf.addEdge(0, 2 + H + y, C[y]); } foreach (x; 0 .. H) foreach (y; 0 .. W) { const u = 2 + H + W + x * W + y; mf.addEdge(2 + x, u, MaxFlow!long.wINF); mf.addEdge(2 + H + y, u, MaxFlow!long.wINF); mf.addEdge(u, 1, G[x][y]); } mf.dinic(0, 1); long ans; ans += R.sum; ans += C.sum; ans -= mf.tof; writeln(ans); } } catch (EOFException e) { } }