結果
問題 | No.1014 competitive fighting |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-03-21 20:44:14 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 200 ms / 2,000 ms |
コード長 | 3,774 bytes |
コンパイル時間 | 1,168 ms |
コンパイル使用メモリ | 138,556 KB |
実行使用メモリ | 20,524 KB |
最終ジャッジ日時 | 2024-06-22 05:47:23 |
合計ジャッジ時間 | 10,928 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 194 ms
20,056 KB |
testcase_06 | AC | 192 ms
19,700 KB |
testcase_07 | AC | 195 ms
19,632 KB |
testcase_08 | AC | 190 ms
19,148 KB |
testcase_09 | AC | 196 ms
19,680 KB |
testcase_10 | AC | 139 ms
18,108 KB |
testcase_11 | AC | 173 ms
17,248 KB |
testcase_12 | AC | 200 ms
20,524 KB |
testcase_13 | AC | 88 ms
11,584 KB |
testcase_14 | AC | 82 ms
11,048 KB |
testcase_15 | AC | 98 ms
12,780 KB |
testcase_16 | AC | 5 ms
6,940 KB |
testcase_17 | AC | 34 ms
6,944 KB |
testcase_18 | AC | 153 ms
18,164 KB |
testcase_19 | AC | 192 ms
20,256 KB |
testcase_20 | AC | 66 ms
7,824 KB |
testcase_21 | AC | 144 ms
17,840 KB |
testcase_22 | AC | 119 ms
17,084 KB |
testcase_23 | AC | 46 ms
6,944 KB |
testcase_24 | AC | 48 ms
7,320 KB |
testcase_25 | AC | 13 ms
6,944 KB |
testcase_26 | AC | 143 ms
18,476 KB |
testcase_27 | AC | 34 ms
6,944 KB |
testcase_28 | AC | 41 ms
6,940 KB |
testcase_29 | AC | 3 ms
6,944 KB |
testcase_30 | AC | 189 ms
20,448 KB |
testcase_31 | AC | 151 ms
18,760 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 12 ms
6,944 KB |
testcase_34 | AC | 137 ms
19,280 KB |
testcase_35 | AC | 178 ms
18,856 KB |
testcase_36 | AC | 124 ms
18,628 KB |
testcase_37 | AC | 6 ms
6,940 KB |
testcase_38 | AC | 113 ms
15,208 KB |
testcase_39 | AC | 59 ms
7,920 KB |
testcase_40 | AC | 106 ms
14,956 KB |
testcase_41 | AC | 74 ms
10,604 KB |
testcase_42 | AC | 159 ms
19,312 KB |
testcase_43 | AC | 10 ms
6,944 KB |
testcase_44 | AC | 151 ms
19,548 KB |
testcase_45 | AC | 93 ms
11,840 KB |
testcase_46 | AC | 16 ms
6,940 KB |
testcase_47 | AC | 50 ms
7,276 KB |
testcase_48 | AC | 126 ms
17,920 KB |
testcase_49 | AC | 6 ms
6,940 KB |
testcase_50 | AC | 160 ms
19,388 KB |
testcase_51 | AC | 98 ms
12,172 KB |
testcase_52 | AC | 7 ms
6,940 KB |
testcase_53 | AC | 199 ms
20,108 KB |
ソースコード
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)); } alias Move = Tuple!(long, "a", long, "b", long, "c", int, "id"); enum INF = 10L^^18; void main() { try { for (; ; ) { const N = readInt(); auto P = new Move[N]; foreach (i; 0 .. N) { P[i].a = readLong(); P[i].b = readLong(); P[i].c = readLong(); P[i].id = i; } P.sort; auto ks = new int[N]; foreach (i; 0 .. N) { ks[i] = P.upperBound(Move(P[i].b - P[i].c, INF, INF, -1)); } debug { writeln("ks = ", ks); } int segN; for (segN = 1; segN < N; segN <<= 1) {} auto dp = new long[segN << 1]; auto mem = new bool[segN << 1]; dp[] = -INF; alias Entry = Tuple!(long, "val", int, "id"); auto ls = new Entry[][](N + 1, 2); ls[0][] = Entry(-INF, -1); foreach (i; 0 .. N) { ls[i + 1][] = ls[i][]; auto e = Entry(P[i].b - P[i].c, i); foreach (j; 0 .. 2) { if (ls[i + 1][j] < e) { swap(ls[i + 1][j], e); } } } foreach (i; 0 .. N) { bool cyc; foreach (j; 0 .. 2) { if (ls[ks[i]][j].id != i && ls[ks[i]][j].val >= P[i].a) { cyc = true; } } if (cyc) { for (int u = segN + i; u > 0; u >>= 1) { debug { writeln("INF ", i, "; ", u); } dp[u] = INF; mem[u] = true; } } } long calc(int u) { if (!mem[u]) { mem[u] = true; if (u < segN) { chmax(dp[u], calc(u << 1)); chmax(dp[u], calc(u << 1 | 1)); } else { const i = u - segN; if (0 <= i && i < N) { dp[u] = 0; void rangeAE(int v, int w) { for (v += segN, w += segN; v < w; v >>= 1, w >>= 1) { if (v & 1) chmax(dp[u], calc(v++)); if (w & 1) chmax(dp[u], calc(--w)); } } if (i < ks[i]) { rangeAE(0, i); rangeAE(i + 1, ks[i]); } else { rangeAE(0, ks[i]); } dp[u] += P[i].b; } } } return dp[u]; } auto ans = new long[N]; foreach (i; 0 .. N) { ans[P[i].id] = calc(segN + i); } foreach (i; 0 .. N) { if (ans[i] >= INF) { writeln("BAN"); } else { writeln(ans[i]); } } } } catch (EOFException e) { } }