結果
問題 | No.962 LCPs |
ユーザー | 👑 hos.lyric |
提出日時 | 2019-12-24 23:19:59 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 2,800 bytes |
コンパイル時間 | 1,035 ms |
コンパイル使用メモリ | 124,796 KB |
実行使用メモリ | 33,500 KB |
最終ジャッジ日時 | 2024-06-22 03:59:54 |
合計ジャッジ時間 | 4,872 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,944 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 165 ms
33,500 KB |
testcase_18 | AC | 82 ms
23,500 KB |
testcase_19 | AC | 81 ms
22,628 KB |
testcase_20 | AC | 55 ms
16,908 KB |
testcase_21 | AC | 54 ms
17,700 KB |
testcase_22 | AC | 42 ms
12,688 KB |
testcase_23 | AC | 42 ms
12,252 KB |
testcase_24 | AC | 35 ms
8,544 KB |
testcase_25 | AC | 34 ms
8,676 KB |
testcase_26 | AC | 29 ms
8,236 KB |
testcase_27 | AC | 45 ms
13,396 KB |
testcase_28 | AC | 30 ms
7,432 KB |
testcase_29 | AC | 25 ms
6,940 KB |
testcase_30 | AC | 41 ms
12,272 KB |
testcase_31 | AC | 52 ms
14,076 KB |
testcase_32 | AC | 24 ms
6,948 KB |
testcase_33 | AC | 78 ms
23,644 KB |
testcase_34 | AC | 31 ms
7,040 KB |
testcase_35 | AC | 28 ms
7,640 KB |
testcase_36 | AC | 36 ms
8,548 KB |
testcase_37 | AC | 16 ms
6,940 KB |
testcase_38 | AC | 16 ms
6,944 KB |
testcase_39 | AC | 16 ms
6,940 KB |
testcase_40 | AC | 16 ms
6,944 KB |
testcase_41 | AC | 16 ms
6,940 KB |
testcase_42 | AC | 16 ms
6,944 KB |
testcase_43 | AC | 17 ms
6,944 KB |
testcase_44 | AC | 16 ms
6,944 KB |
testcase_45 | AC | 17 ms
6,940 KB |
testcase_46 | AC | 16 ms
6,944 KB |
testcase_47 | AC | 3 ms
6,944 KB |
testcase_48 | AC | 3 ms
6,940 KB |
testcase_49 | AC | 3 ms
6,944 KB |
testcase_50 | AC | 3 ms
6,944 KB |
testcase_51 | AC | 3 ms
6,944 KB |
testcase_52 | AC | 2 ms
6,940 KB |
testcase_53 | AC | 3 ms
6,944 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 2 ms
6,944 KB |
testcase_56 | AC | 3 ms
6,944 KB |
testcase_57 | AC | 4 ms
6,940 KB |
testcase_58 | AC | 4 ms
6,940 KB |
testcase_59 | AC | 3 ms
6,940 KB |
testcase_60 | AC | 4 ms
6,944 KB |
testcase_61 | AC | 4 ms
6,944 KB |
testcase_62 | AC | 4 ms
6,940 KB |
testcase_63 | AC | 101 ms
27,436 KB |
testcase_64 | AC | 3 ms
6,940 KB |
testcase_65 | AC | 107 ms
24,048 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)); } enum INF = 10^^9; int N; string[] S; int[] L, C; int segN; Tuple!(int, int)[] seg; Tuple!(int, int) segRangeMin(int a, int b) { auto ret = tuple(INF, -1); for (a += segN, b += segN; a < b; a >>= 1, b >>= 1) { if (a & 1) chmin(ret, seg[a++]); if (b & 1) chmin(ret, seg[--b]); } return ret; } long solve(int l, int r) { if (l == r) { return L[l]; } else { const res = segRangeMin(l, r); const c = res[0]; const mid = res[1]; long ret; ret += solve(l, mid); ret += solve(mid + 1, r); const long a = mid - l + 1, b = r - mid; ret += c * (a * (a + 1) / 2) * b; ret += c * a * (b * (b + 1) / 2); debug { writeln("solve ", l, " ", r, ": ", mid, "; ", ret); } return ret; } } void main() { try { for (; ; ) { N = readInt(); S = new string[N]; foreach (i; 0 .. N) { S[i] = readToken(); } L = new int[N]; foreach (i; 0 .. N) { L[i] = cast(int)(S[i].length); } C = new int[N - 1]; foreach (i; 0 .. N - 1) { int x; for (x = 0; x < L[i] && x < L[i + 1] && S[i][x] == S[i + 1][x]; ++x) {} C[i] = x; } debug { writeln("L = ", L); writeln("C = ", C); } for (segN = 1; segN < N; segN <<= 1) {} seg.length = segN << 1; foreach (i; 0 .. N - 1) { seg[segN + i] = tuple(C[i], i); } foreach_reverse (a; 1 .. segN) { seg[a] = min(seg[a << 1], seg[a << 1 | 1]); } const res = solve(0, N - 1); writeln(res); } } catch (EOFException e) { } }