結果
問題 | No.2606 Mirror Relay |
ユーザー | 👑 amentorimaru |
提出日時 | 2023-11-02 00:59:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 327 ms / 2,000 ms |
コード長 | 2,190 bytes |
コンパイル時間 | 332 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 201,600 KB |
最終ジャッジ日時 | 2024-09-27 17:43:09 |
合計ジャッジ時間 | 10,096 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,208 KB |
testcase_01 | AC | 40 ms
53,688 KB |
testcase_02 | AC | 39 ms
52,540 KB |
testcase_03 | AC | 41 ms
53,508 KB |
testcase_04 | AC | 54 ms
64,372 KB |
testcase_05 | AC | 52 ms
64,048 KB |
testcase_06 | AC | 53 ms
64,788 KB |
testcase_07 | AC | 53 ms
64,616 KB |
testcase_08 | AC | 53 ms
65,356 KB |
testcase_09 | AC | 53 ms
64,748 KB |
testcase_10 | AC | 53 ms
65,380 KB |
testcase_11 | AC | 55 ms
65,004 KB |
testcase_12 | AC | 59 ms
67,404 KB |
testcase_13 | AC | 54 ms
65,000 KB |
testcase_14 | AC | 44 ms
53,444 KB |
testcase_15 | AC | 42 ms
53,780 KB |
testcase_16 | AC | 42 ms
54,068 KB |
testcase_17 | AC | 42 ms
53,812 KB |
testcase_18 | AC | 41 ms
53,212 KB |
testcase_19 | AC | 74 ms
74,008 KB |
testcase_20 | AC | 73 ms
72,688 KB |
testcase_21 | AC | 75 ms
72,528 KB |
testcase_22 | AC | 78 ms
74,956 KB |
testcase_23 | AC | 74 ms
72,684 KB |
testcase_24 | AC | 76 ms
74,308 KB |
testcase_25 | AC | 68 ms
70,272 KB |
testcase_26 | AC | 59 ms
67,228 KB |
testcase_27 | AC | 71 ms
72,544 KB |
testcase_28 | AC | 74 ms
74,224 KB |
testcase_29 | AC | 56 ms
64,848 KB |
testcase_30 | AC | 54 ms
64,756 KB |
testcase_31 | AC | 58 ms
66,620 KB |
testcase_32 | AC | 60 ms
66,568 KB |
testcase_33 | AC | 60 ms
67,896 KB |
testcase_34 | AC | 53 ms
64,312 KB |
testcase_35 | AC | 57 ms
65,876 KB |
testcase_36 | AC | 58 ms
66,960 KB |
testcase_37 | AC | 54 ms
65,696 KB |
testcase_38 | AC | 53 ms
64,800 KB |
testcase_39 | AC | 147 ms
89,912 KB |
testcase_40 | AC | 149 ms
89,784 KB |
testcase_41 | AC | 148 ms
90,008 KB |
testcase_42 | AC | 153 ms
89,884 KB |
testcase_43 | AC | 151 ms
89,884 KB |
testcase_44 | AC | 154 ms
90,240 KB |
testcase_45 | AC | 149 ms
90,536 KB |
testcase_46 | AC | 150 ms
90,148 KB |
testcase_47 | AC | 150 ms
88,856 KB |
testcase_48 | AC | 151 ms
90,256 KB |
testcase_49 | AC | 216 ms
116,216 KB |
testcase_50 | AC | 219 ms
117,844 KB |
testcase_51 | AC | 219 ms
120,660 KB |
testcase_52 | AC | 188 ms
110,008 KB |
testcase_53 | AC | 199 ms
120,100 KB |
testcase_54 | AC | 220 ms
115,316 KB |
testcase_55 | AC | 253 ms
140,292 KB |
testcase_56 | AC | 215 ms
117,212 KB |
testcase_57 | AC | 192 ms
110,832 KB |
testcase_58 | AC | 233 ms
125,672 KB |
testcase_59 | AC | 152 ms
91,220 KB |
testcase_60 | AC | 159 ms
90,184 KB |
testcase_61 | AC | 151 ms
90,292 KB |
testcase_62 | AC | 150 ms
90,204 KB |
testcase_63 | AC | 156 ms
90,440 KB |
testcase_64 | AC | 150 ms
90,192 KB |
testcase_65 | AC | 155 ms
90,612 KB |
testcase_66 | AC | 153 ms
90,332 KB |
testcase_67 | AC | 153 ms
90,352 KB |
testcase_68 | AC | 153 ms
90,548 KB |
testcase_69 | AC | 327 ms
201,600 KB |
testcase_70 | AC | 39 ms
52,676 KB |
testcase_71 | AC | 40 ms
52,860 KB |
testcase_72 | AC | 38 ms
52,820 KB |
ソースコード
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)): 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=[-1]*nodeCount score[0]=0 score[1]=0 for i in range(nodeCount): if score[i]!=-1: continue stk=[i] while score[stk[-1]]==-1: stk.append(pt.parent[stk[-1]]) tmp=score[stk[-1]] stk.pop() for v in stk[::-1]: tmp+=pt.length[v]*count[v] score[v]=tmp print(max(score)) if __name__ == "__main__": main()