結果

問題 No.2606 Mirror Relay
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-11-09 00:04:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 1,952 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 197,176 KB
最終ジャッジ日時 2024-01-02 13:43:43
合計ジャッジ時間 9,245 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 49 ms
64,216 KB
testcase_05 AC 49 ms
64,216 KB
testcase_06 AC 48 ms
64,220 KB
testcase_07 AC 48 ms
64,216 KB
testcase_08 AC 48 ms
64,220 KB
testcase_09 AC 50 ms
64,232 KB
testcase_10 AC 49 ms
64,216 KB
testcase_11 AC 48 ms
64,216 KB
testcase_12 AC 48 ms
64,216 KB
testcase_13 AC 49 ms
64,220 KB
testcase_14 AC 38 ms
53,460 KB
testcase_15 AC 38 ms
53,460 KB
testcase_16 AC 37 ms
53,460 KB
testcase_17 AC 37 ms
53,460 KB
testcase_18 AC 38 ms
53,460 KB
testcase_19 AC 68 ms
73,336 KB
testcase_20 AC 63 ms
71,224 KB
testcase_21 AC 63 ms
71,244 KB
testcase_22 AC 75 ms
74,372 KB
testcase_23 AC 66 ms
71,260 KB
testcase_24 AC 64 ms
71,244 KB
testcase_25 AC 59 ms
68,516 KB
testcase_26 AC 53 ms
66,432 KB
testcase_27 AC 63 ms
70,716 KB
testcase_28 AC 65 ms
71,232 KB
testcase_29 AC 49 ms
64,228 KB
testcase_30 AC 51 ms
64,228 KB
testcase_31 AC 50 ms
64,228 KB
testcase_32 AC 52 ms
66,296 KB
testcase_33 AC 51 ms
66,296 KB
testcase_34 AC 52 ms
66,296 KB
testcase_35 AC 48 ms
64,228 KB
testcase_36 AC 53 ms
66,316 KB
testcase_37 AC 52 ms
66,320 KB
testcase_38 AC 54 ms
66,320 KB
testcase_39 AC 135 ms
89,840 KB
testcase_40 AC 137 ms
89,708 KB
testcase_41 AC 136 ms
89,628 KB
testcase_42 AC 140 ms
90,100 KB
testcase_43 AC 137 ms
89,708 KB
testcase_44 AC 136 ms
89,632 KB
testcase_45 AC 137 ms
89,720 KB
testcase_46 AC 136 ms
89,928 KB
testcase_47 AC 136 ms
90,044 KB
testcase_48 AC 137 ms
89,728 KB
testcase_49 AC 190 ms
116,644 KB
testcase_50 AC 199 ms
117,932 KB
testcase_51 AC 193 ms
120,704 KB
testcase_52 AC 169 ms
109,404 KB
testcase_53 AC 180 ms
117,592 KB
testcase_54 AC 196 ms
116,876 KB
testcase_55 AC 222 ms
138,416 KB
testcase_56 AC 191 ms
117,764 KB
testcase_57 AC 166 ms
110,624 KB
testcase_58 AC 206 ms
123,340 KB
testcase_59 AC 140 ms
90,044 KB
testcase_60 AC 138 ms
90,380 KB
testcase_61 AC 134 ms
89,696 KB
testcase_62 AC 139 ms
89,920 KB
testcase_63 AC 136 ms
90,048 KB
testcase_64 AC 134 ms
89,904 KB
testcase_65 AC 141 ms
90,036 KB
testcase_66 AC 135 ms
89,912 KB
testcase_67 AC 139 ms
90,056 KB
testcase_68 AC 137 ms
90,280 KB
testcase_69 AC 275 ms
197,176 KB
testcase_70 AC 37 ms
53,460 KB
testcase_71 AC 36 ms
53,460 KB
testcase_72 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
def read_values(): return tuple(map(int, input().split()))
def read_list(): return list(map(int, input().split()))

class PalindromicTree:
    def __init__(self):
        self.st=[]
        self.length=[-1,0]
        self.parent=[0,0]
        self.count=[0,0]
        self.link=[dict() for _ in range(2)]
        self.lastNodeIdx=0
        
    def add(self,v):
        self.st.append(v)
        prevNodeIdx=self.lastNodeIdx
        nextNodeIdx=self.lastNodeIdx
        while True:
            head = self.length[nextNodeIdx] + 2
            if head <= len(self.st) and self.st[-head]==self.st[-1]:
                break
            nextNodeIdx=self.parent[nextNodeIdx]
        nextLen=self.length[nextNodeIdx]+2
        if v in self.link[nextNodeIdx].keys():
            self.lastNodeIdx=self.link[nextNodeIdx][v]
            self.count[self.lastNodeIdx]+=1
            return
        self.lastNodeIdx=len(self.length)
        self.length.append(nextLen)
        if self.length[-1]==1:
            self.parent.append(1)
        else:
            prevNodeIdx=self.parent[nextNodeIdx]
            while True:
                head = self.length[prevNodeIdx] + 2
                if head <= len(self.st) and self.st[-head]==self.st[-1]:
                    break
                prevNodeIdx=self.parent[prevNodeIdx]
            self.parent.append(self.link[prevNodeIdx][v])
        self.count.append(1)
        self.link[nextNodeIdx][v]=self.lastNodeIdx
        self.link.append(dict())

def main():  
    s=input()
    pt = PalindromicTree()
    for i in range(len(s)-1,-1,-1):
        pt.add(s[i])
    nodeCount = len(pt.length)
    count=pt.count[:]
    for i in range(nodeCount-1,1,-1):
        count[pt.parent[i]]+=count[i]
    score=[0]*nodeCount
    for i in range(2,nodeCount):
        score[i]=score[pt.parent[i]]+pt.length[i]*count[i]
    print(max(score))
            
if __name__ == "__main__":
    main()
0