結果

問題 No.962 LCPs
ユーザー maspymaspy
提出日時 2020-03-18 21:45:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 482 ms / 2,000 ms
コード長 827 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 48,692 KB
最終ジャッジ日時 2023-08-20 20:15:45
合計ジャッジ時間 9,874 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,312 KB
testcase_01 AC 17 ms
8,332 KB
testcase_02 AC 19 ms
8,504 KB
testcase_03 AC 18 ms
8,264 KB
testcase_04 AC 18 ms
8,184 KB
testcase_05 AC 18 ms
8,176 KB
testcase_06 AC 17 ms
8,248 KB
testcase_07 AC 18 ms
8,168 KB
testcase_08 AC 17 ms
8,192 KB
testcase_09 AC 17 ms
8,336 KB
testcase_10 AC 17 ms
8,332 KB
testcase_11 AC 17 ms
8,296 KB
testcase_12 AC 17 ms
8,252 KB
testcase_13 AC 16 ms
8,248 KB
testcase_14 AC 16 ms
8,152 KB
testcase_15 AC 17 ms
8,248 KB
testcase_16 AC 16 ms
8,356 KB
testcase_17 AC 482 ms
48,692 KB
testcase_18 AC 286 ms
32,996 KB
testcase_19 AC 292 ms
33,064 KB
testcase_20 AC 218 ms
24,840 KB
testcase_21 AC 220 ms
24,976 KB
testcase_22 AC 182 ms
20,616 KB
testcase_23 AC 178 ms
20,616 KB
testcase_24 AC 160 ms
18,076 KB
testcase_25 AC 160 ms
18,020 KB
testcase_26 AC 146 ms
16,340 KB
testcase_27 AC 195 ms
22,144 KB
testcase_28 AC 149 ms
17,012 KB
testcase_29 AC 138 ms
15,580 KB
testcase_30 AC 176 ms
20,012 KB
testcase_31 AC 216 ms
22,872 KB
testcase_32 AC 130 ms
15,076 KB
testcase_33 AC 284 ms
31,960 KB
testcase_34 AC 150 ms
17,060 KB
testcase_35 AC 145 ms
16,616 KB
testcase_36 AC 170 ms
17,944 KB
testcase_37 AC 100 ms
12,976 KB
testcase_38 AC 98 ms
12,888 KB
testcase_39 AC 99 ms
12,968 KB
testcase_40 AC 101 ms
13,084 KB
testcase_41 AC 101 ms
12,968 KB
testcase_42 AC 100 ms
12,964 KB
testcase_43 AC 103 ms
12,968 KB
testcase_44 AC 105 ms
13,060 KB
testcase_45 AC 100 ms
12,984 KB
testcase_46 AC 96 ms
13,020 KB
testcase_47 AC 18 ms
8,452 KB
testcase_48 AC 17 ms
8,460 KB
testcase_49 AC 17 ms
8,332 KB
testcase_50 AC 17 ms
8,472 KB
testcase_51 AC 17 ms
8,536 KB
testcase_52 AC 16 ms
8,436 KB
testcase_53 AC 17 ms
8,464 KB
testcase_54 AC 17 ms
8,480 KB
testcase_55 AC 17 ms
8,436 KB
testcase_56 AC 18 ms
8,548 KB
testcase_57 AC 64 ms
8,356 KB
testcase_58 AC 60 ms
8,460 KB
testcase_59 AC 60 ms
8,488 KB
testcase_60 AC 73 ms
8,420 KB
testcase_61 AC 73 ms
8,356 KB
testcase_62 AC 72 ms
8,516 KB
testcase_63 AC 319 ms
34,892 KB
testcase_64 AC 17 ms
8,444 KB
testcase_65 AC 312 ms
34,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from operator import itemgetter

N = int(readline())
S = read().split()

answer = 0
for word in S:
    answer += len(word)

LCP = [0] * (N - 1)
for i, (w1, w2) in enumerate(zip(S, S[1:])):
    L1 = len(w1)
    L2 = len(w2)
    j = 0
    while j < L1 and j < L2 and w1[j] == w2[j]:
        j += 1
    LCP[i] = j

INF = 10 ** 6
LCP.insert(0, -INF)
LCP.append(-INF)
values = sorted(enumerate(LCP), key=itemgetter(1), reverse=True)

left = list(range(1, N + 2))
right = list(range(-1, N))


for i, value in values[:-2]:
    l = left[i - 1]
    r = right[i + 1]
    left[r] = l
    right[l] = r
    cnt = (i - l + 1) * (r - i + 1)
    answer += value * cnt * (r - l + 4) // 2

print(answer)
0