結果

問題 No.962 LCPs
ユーザー mkawa2mkawa2
提出日時 2019-12-25 20:52:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,319 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 81,728 KB
実行使用メモリ 214,108 KB
最終ジャッジ日時 2023-10-26 03:26:40
合計ジャッジ時間 5,845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
57,816 KB
testcase_01 AC 38 ms
53,468 KB
testcase_02 AC 160 ms
75,932 KB
testcase_03 AC 95 ms
75,708 KB
testcase_04 AC 76 ms
75,616 KB
testcase_05 AC 70 ms
75,592 KB
testcase_06 AC 70 ms
75,448 KB
testcase_07 AC 82 ms
75,672 KB
testcase_08 AC 82 ms
75,672 KB
testcase_09 AC 77 ms
75,680 KB
testcase_10 AC 82 ms
75,664 KB
testcase_11 AC 71 ms
75,428 KB
testcase_12 AC 38 ms
53,468 KB
testcase_13 AC 38 ms
53,468 KB
testcase_14 AC 38 ms
53,468 KB
testcase_15 AC 38 ms
53,468 KB
testcase_16 AC 38 ms
53,468 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

class SparseTable:
    def __init__(self, aa):
        w = len(aa)
        h = w.bit_length()
        table = [aa] + [[""] * w for _ in range(h - 1)]
        tablei1 = table[0]
        for i in range(1, h):
            tablei = table[i]
            for j in range(w-(1<<i)+1):
                rj = j + (1 << (i - 1))
                tablei[j] = self.make_lcp(tablei1[j], tablei1[rj])
            tablei1 = tablei
        self.table = table
        #print(table)

    def make_lcp(self,s,t):
        res=""
        for c0,c1 in zip(s,t):
            if c0!=c1:break
            res+=c0
        return res

    def lcp(self, l, r):
        i = (r - l).bit_length() - 1
        tablei = self.table[i]
        Lmin = tablei[l]
        Rmin = tablei[r - (1 << i)]
        res=self.make_lcp(Lmin,Rmin)
        return res

def main():
    n=int(input())
    ss=[input() for _ in range(n)]
    sp=SparseTable(ss)
    ans=0
    for j in range(n+1):
        for i in range(j):
            ans+=len(sp.lcp(i,j))*(j-i)
    print(ans)

main()
0