結果

問題 No.962 LCPs
ユーザー H3PO4H3PO4
提出日時 2021-07-25 16:27:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 568 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 78,412 KB
最終ジャッジ日時 2023-09-28 06:15:28
合計ジャッジ時間 20,690 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
12,388 KB
testcase_01 AC 41 ms
12,276 KB
testcase_02 AC 42 ms
12,368 KB
testcase_03 AC 47 ms
12,364 KB
testcase_04 AC 41 ms
12,352 KB
testcase_05 AC 41 ms
12,324 KB
testcase_06 AC 43 ms
12,276 KB
testcase_07 AC 44 ms
12,272 KB
testcase_08 AC 42 ms
12,288 KB
testcase_09 AC 41 ms
12,400 KB
testcase_10 AC 41 ms
12,288 KB
testcase_11 AC 41 ms
12,280 KB
testcase_12 AC 43 ms
12,272 KB
testcase_13 AC 43 ms
12,268 KB
testcase_14 AC 44 ms
12,400 KB
testcase_15 AC 45 ms
12,392 KB
testcase_16 AC 43 ms
12,272 KB
testcase_17 AC 506 ms
12,440 KB
testcase_18 AC 358 ms
12,392 KB
testcase_19 AC 372 ms
12,284 KB
testcase_20 AC 307 ms
12,368 KB
testcase_21 AC 301 ms
12,284 KB
testcase_22 AC 275 ms
12,360 KB
testcase_23 AC 270 ms
12,444 KB
testcase_24 AC 245 ms
12,360 KB
testcase_25 AC 255 ms
12,384 KB
testcase_26 AC 237 ms
12,284 KB
testcase_27 AC 274 ms
12,404 KB
testcase_28 AC 245 ms
12,268 KB
testcase_29 AC 238 ms
12,340 KB
testcase_30 AC 269 ms
12,280 KB
testcase_31 AC 291 ms
12,388 KB
testcase_32 AC 229 ms
12,340 KB
testcase_33 AC 343 ms
12,444 KB
testcase_34 AC 237 ms
12,392 KB
testcase_35 AC 244 ms
12,444 KB
testcase_36 AC 251 ms
12,444 KB
testcase_37 AC 315 ms
32,084 KB
testcase_38 AC 315 ms
31,928 KB
testcase_39 AC 316 ms
31,896 KB
testcase_40 AC 325 ms
31,936 KB
testcase_41 AC 314 ms
31,876 KB
testcase_42 AC 312 ms
31,820 KB
testcase_43 AC 314 ms
31,936 KB
testcase_44 AC 326 ms
31,820 KB
testcase_45 AC 319 ms
31,808 KB
testcase_46 AC 322 ms
31,928 KB
testcase_47 AC 427 ms
63,380 KB
testcase_48 AC 386 ms
57,412 KB
testcase_49 AC 485 ms
70,920 KB
testcase_50 AC 532 ms
73,344 KB
testcase_51 AC 429 ms
64,308 KB
testcase_52 AC 304 ms
48,828 KB
testcase_53 AC 446 ms
65,764 KB
testcase_54 AC 385 ms
57,748 KB
testcase_55 AC 290 ms
45,888 KB
testcase_56 AC 556 ms
75,540 KB
testcase_57 AC 150 ms
12,284 KB
testcase_58 AC 147 ms
12,340 KB
testcase_59 AC 150 ms
12,388 KB
testcase_60 AC 177 ms
12,280 KB
testcase_61 AC 182 ms
12,320 KB
testcase_62 AC 184 ms
12,384 KB
testcase_63 AC 334 ms
12,356 KB
testcase_64 AC 568 ms
78,412 KB
testcase_65 AC 333 ms
12,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from dataclasses import dataclass, field

N = int(input())
ans = 0

tri = lambda x: x * (x + 1) // 2


@dataclass
class TrieNode:
    num: int
    last: int
    seq: int
    child: dict = field(default_factory=dict)


G = [None] * (2 * 10 ** 5 + 1)
G[0] = TrieNode(num=0, last=0, seq=0)

nodenum = 1
for i in range(N):
    S = input()
    pointer = 0
    for s in S:
        if s not in G[pointer].child:
            G[pointer].child[s] = nodenum
            G[nodenum] = TrieNode(num=nodenum, last=i - 1, seq=0)
            nodenum += 1
        pointer = G[pointer].child[s]
        if G[pointer].last == i - 1:
            G[pointer].seq += 1
        else:
            G[pointer].seq = 1
        ans += tri(G[pointer].seq)
        G[pointer].last = i
print(ans)
0