結果
問題 | No.913 木の燃やし方 |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-10-18 22:46:59 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,638 bytes |
コンパイル時間 | 873 ms |
コンパイル使用メモリ | 123,708 KB |
実行使用メモリ | 43,572 KB |
最終ジャッジ日時 | 2023-09-04 03:06:25 |
合計ジャッジ時間 | 14,927 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 6 ms
5,240 KB |
testcase_06 | WA | - |
testcase_07 | AC | 3 ms
4,380 KB |
testcase_08 | AC | 302 ms
34,192 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 327 ms
39,416 KB |
testcase_13 | AC | 228 ms
36,316 KB |
testcase_14 | AC | 218 ms
35,908 KB |
testcase_15 | AC | 216 ms
35,880 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 315 ms
31,948 KB |
testcase_20 | AC | 339 ms
33,740 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 318 ms
34,060 KB |
testcase_25 | AC | 281 ms
32,136 KB |
testcase_26 | AC | 232 ms
38,356 KB |
testcase_27 | AC | 233 ms
38,736 KB |
testcase_28 | AC | 232 ms
36,328 KB |
testcase_29 | AC | 215 ms
36,496 KB |
testcase_30 | AC | 319 ms
34,396 KB |
testcase_31 | AC | 263 ms
41,236 KB |
testcase_32 | AC | 247 ms
43,572 KB |
testcase_33 | AC | 237 ms
39,304 KB |
testcase_34 | AC | 297 ms
37,280 KB |
testcase_35 | AC | 306 ms
38,600 KB |
testcase_36 | AC | 348 ms
35,152 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, 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)); } enum INF = 10L^^18; int N; long[] A; long[] ASum; alias Entry = Tuple!(long, int); Entry[][] es; long f(int i, int j) { return (cast(long)(j - i))^^2 + (ASum[j] - ASum[i]); } void solve(int dir, int iL, int iR, int jL, int jR) { if (iL == iR) return; const iMid = (iL + iR) / 2; long opt = INF; int jm = jL; foreach (j; jL .. jR) { if (iMid < j) { if (chmin(opt, f(iMid, j))) { jm = j; } } } if (dir == 0) { es[iMid] ~= Entry(opt, jm); } else { es[N - jm] ~= Entry(opt, N - iMid); } solve(dir, iL, iMid, jL, jm + 1); solve(dir, iMid + 1, iR, jm, jR); } void main() { try { for (; ; ) { N = readInt(); A = new long[N]; foreach (i; 0 .. N) { A[i] = readLong(); } es = new Entry[][N]; foreach (dir; 0 .. 2) { ASum = new long[N + 1]; foreach (i; 0 .. N) { ASum[i + 1] = ASum[i] + A[i]; } solve(dir, 0, N, 0, N + 1); A.reverse(); } debug { writeln("es = ", es); } BinaryHeap!(Array!Entry, "a > b") que; auto ans = new long[N]; foreach (i; 0 .. N) { foreach (e; es[i]) { que.insert(e); } for (; !que.empty; que.removeFront) { if (i < que.front[1]) { ans[i] = que.front[0]; break; } } } foreach (i; 0 .. N) { writeln(ans[i]); } } } catch (EOFException e) { } }