結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-04-06 17:34:11 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 220 ms / 2,000 ms |
コード長 | 2,672 bytes |
コンパイル時間 | 1,059 ms |
コンパイル使用メモリ | 126,336 KB |
実行使用メモリ | 33,204 KB |
最終ジャッジ日時 | 2024-06-13 04:52:26 |
合計ジャッジ時間 | 8,015 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 29 ms
6,912 KB |
testcase_14 | AC | 32 ms
7,348 KB |
testcase_15 | AC | 87 ms
19,424 KB |
testcase_16 | AC | 162 ms
22,656 KB |
testcase_17 | AC | 147 ms
23,680 KB |
testcase_18 | AC | 24 ms
6,784 KB |
testcase_19 | AC | 198 ms
31,964 KB |
testcase_20 | AC | 72 ms
16,372 KB |
testcase_21 | AC | 198 ms
32,188 KB |
testcase_22 | AC | 70 ms
13,696 KB |
testcase_23 | AC | 199 ms
32,252 KB |
testcase_24 | AC | 49 ms
11,456 KB |
testcase_25 | AC | 201 ms
32,756 KB |
testcase_26 | AC | 23 ms
6,656 KB |
testcase_27 | AC | 151 ms
24,064 KB |
testcase_28 | AC | 136 ms
20,736 KB |
testcase_29 | AC | 73 ms
14,080 KB |
testcase_30 | AC | 208 ms
31,248 KB |
testcase_31 | AC | 28 ms
7,296 KB |
testcase_32 | AC | 32 ms
7,424 KB |
testcase_33 | AC | 219 ms
30,980 KB |
testcase_34 | AC | 214 ms
30,984 KB |
testcase_35 | AC | 220 ms
31,072 KB |
testcase_36 | AC | 209 ms
33,204 KB |
testcase_37 | AC | 206 ms
22,912 KB |
testcase_38 | AC | 217 ms
30,980 KB |
ソースコード
import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, 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)); } enum INF = 10L^^18; int N; long K; long[] T, D; long solve(long dLim) { debug { writeln("solve ", dLim); } int[] xs; xs ~= 0; foreach (i; 1 .. N + 1) { if (D[i] > dLim) { xs ~= i; } } xs ~= N + 1; const len = cast(int)(xs.length) - 1; debug { writeln(" xs = ", xs); } long ans = D.sum; auto dp = new long[N + 2]; foreach (j; 0 .. len) { if (T[xs[j + 1]] - T[xs[j]] < K) { return INF; } dp[xs[j]] = 0; long dpMax = -1; for (int l = xs[j], r = xs[j] + 1; r <= xs[j + 1]; ++r) { for (; T[r] - T[l] >= K; ++l) { chmax(dpMax, dp[l]); } dp[r] = (dpMax >= 0) ? (dpMax + D[r]) : -1; } debug { writefln(" dp[%s, %s] = %s", xs[j], xs[j + 1], dp[xs[j] .. xs[j + 1] + 1]); } assert(dp[xs[j + 1]] >= 0); ans -= dp[xs[j + 1]]; } return ans; } void main() { try { for (; ; ) { N = readInt(); K = readLong(); T = new long[N + 2]; D = new long[N + 2]; foreach (i; 1 .. N + 1) { T[i] = readLong(); D[i] = readLong(); } T[0] = T[1] - K; T[N + 1] = T[N] + K; D[0] = D[N + 1] = 0; auto ds = D.dup; ds = ds.sort.uniq.array; int lo = -1, hi = cast(int)(ds.length) - 1; for (; lo + 1 < hi; ) { const mid = (lo + hi) / 2; (solve(ds[mid]) < INF) ? (hi = mid) : (lo = mid); } const ans = solve(ds[hi]); writeln(ds[hi]); writeln(ans); } } catch (EOFException e) { } }