結果
問題 | No.2102 [Cherry Alpha *] Conditional Reflection |
ユーザー | Navier_Boltzmann |
提出日時 | 2023-11-29 15:39:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,296 ms / 3,000 ms |
コード長 | 2,637 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 82,268 KB |
実行使用メモリ | 415,612 KB |
最終ジャッジ日時 | 2024-09-26 13:28:40 |
合計ジャッジ時間 | 110,112 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,832 KB |
testcase_01 | AC | 46 ms
56,704 KB |
testcase_02 | AC | 1,887 ms
260,948 KB |
testcase_03 | AC | 1,616 ms
261,088 KB |
testcase_04 | AC | 1,369 ms
235,696 KB |
testcase_05 | AC | 1,090 ms
142,176 KB |
testcase_06 | AC | 1,426 ms
247,948 KB |
testcase_07 | AC | 1,455 ms
264,396 KB |
testcase_08 | AC | 616 ms
87,444 KB |
testcase_09 | AC | 1,392 ms
265,456 KB |
testcase_10 | AC | 921 ms
127,640 KB |
testcase_11 | AC | 658 ms
165,228 KB |
testcase_12 | AC | 1,118 ms
232,460 KB |
testcase_13 | AC | 1,783 ms
275,960 KB |
testcase_14 | AC | 1,180 ms
193,172 KB |
testcase_15 | AC | 1,592 ms
262,780 KB |
testcase_16 | AC | 2,089 ms
275,848 KB |
testcase_17 | AC | 962 ms
266,952 KB |
testcase_18 | AC | 1,522 ms
278,544 KB |
testcase_19 | AC | 903 ms
166,588 KB |
testcase_20 | AC | 1,899 ms
276,784 KB |
testcase_21 | AC | 891 ms
93,376 KB |
testcase_22 | AC | 2,145 ms
274,932 KB |
testcase_23 | AC | 2,208 ms
274,068 KB |
testcase_24 | AC | 2,296 ms
274,580 KB |
testcase_25 | AC | 2,225 ms
275,832 KB |
testcase_26 | AC | 2,168 ms
275,712 KB |
testcase_27 | AC | 2,175 ms
275,980 KB |
testcase_28 | AC | 2,130 ms
276,180 KB |
testcase_29 | AC | 2,148 ms
275,532 KB |
testcase_30 | AC | 2,147 ms
276,348 KB |
testcase_31 | AC | 2,177 ms
275,308 KB |
testcase_32 | AC | 2,238 ms
275,064 KB |
testcase_33 | AC | 2,134 ms
275,092 KB |
testcase_34 | AC | 2,153 ms
274,368 KB |
testcase_35 | AC | 2,156 ms
274,236 KB |
testcase_36 | AC | 2,230 ms
275,844 KB |
testcase_37 | AC | 2,109 ms
275,688 KB |
testcase_38 | AC | 2,139 ms
274,536 KB |
testcase_39 | AC | 2,140 ms
273,624 KB |
testcase_40 | AC | 2,151 ms
275,288 KB |
testcase_41 | AC | 2,152 ms
273,844 KB |
testcase_42 | AC | 1,564 ms
184,480 KB |
testcase_43 | AC | 1,606 ms
185,272 KB |
testcase_44 | AC | 1,608 ms
184,948 KB |
testcase_45 | AC | 1,543 ms
184,776 KB |
testcase_46 | AC | 1,612 ms
184,924 KB |
testcase_47 | AC | 1,673 ms
274,812 KB |
testcase_48 | AC | 1,573 ms
275,236 KB |
testcase_49 | AC | 1,635 ms
274,680 KB |
testcase_50 | AC | 1,618 ms
275,272 KB |
testcase_51 | AC | 1,580 ms
275,268 KB |
testcase_52 | AC | 1,280 ms
415,512 KB |
testcase_53 | AC | 1,357 ms
415,144 KB |
testcase_54 | AC | 1,291 ms
415,612 KB |
testcase_55 | AC | 1,310 ms
276,960 KB |
testcase_56 | AC | 1,326 ms
277,156 KB |
testcase_57 | AC | 1,324 ms
277,308 KB |
testcase_58 | AC | 625 ms
214,180 KB |
testcase_59 | AC | 2,085 ms
277,908 KB |
testcase_60 | AC | 659 ms
82,556 KB |
testcase_61 | AC | 1,343 ms
277,464 KB |
testcase_62 | AC | 194 ms
79,604 KB |
testcase_63 | AC | 774 ms
79,704 KB |
testcase_64 | AC | 759 ms
79,060 KB |
testcase_65 | AC | 797 ms
80,164 KB |
testcase_66 | AC | 1,315 ms
277,036 KB |
testcase_67 | AC | 1,341 ms
84,040 KB |
testcase_68 | AC | 585 ms
81,092 KB |
testcase_69 | AC | 1,325 ms
84,808 KB |
ソースコード
from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) class Rolling_hash(): def __init__(self,S,mod_list = [1000000009,998244353,3000012541],base_num_list=[500009,500029,500041]): self.n = len(mod_list) self.S = S self.N = len(self.S) self.H = [[0]*(self.N+1) for _ in range(self.n)] self.b_inv = [[1]*self.N for _ in range(self.n)] self.b = [[1]*self.N for _ in range(self.n)] self.mod_list = mod_list for j in range(self.n): tb = base_num_list[j] base_num = base_num_list[j] mod = mod_list[j] tb_inv = 1 base_inv = pow(base_num,mod-2,mod) tH = self.S[0] self.H[j][1] = tH for i in range(self.N-1): tH = (tH + self.S[i+1]*tb)%mod self.H[j][i+2] = tH self.b[j][i+1] = tb tb = (tb*base_num)%mod tb_inv *= base_inv tb_inv %= mod self.b_inv[j][i+1] = tb_inv # self.b[j][i+1] = tb def query(self,j,l,r): if l==r: return 0 tmp = (self.H[j][r]-self.H[j][l])*self.b_inv[j][l]%self.mod_list[j] return tmp X = [set(),set(),set()] for _ in range(N): s = list(input())[:-1] s = [ord(i)-ord('a')+1 for i in s] + [0] rh = Rolling_hash(s) n = len(s) - 1 v0,v1,v2 = rh.query(0,0,n),rh.query(1,0,n),rh.query(2,0,n) if (v0 in X[0])&(v1 in X[1])&(v2 in X[2]): print('Yes') else: print('No') X[0].add(v0) X[1].add(v1) X[2].add(v2) # print(_,v0,v1) for i in range(n-1): flg = 0 v0 = (rh.query(flg,0,i) + rh.query(flg,i,i+1)*rh.b[flg][i+1] + rh.query(flg,i+1,i+2)*rh.b[flg][i] + rh.query(flg,i+2,n)*rh.b[flg][i+2])%rh.mod_list[flg] X[0].add(v0) flg = 1 v1 = (rh.query(flg,0,i) + rh.query(flg,i,i+1)*rh.b[flg][i+1] + rh.query(flg,i+1,i+2)*rh.b[flg][i] + rh.query(flg,i+2,n)*rh.b[flg][i+2])%rh.mod_list[flg] X[1].add(v1) flg = 2 v2 = (rh.query(flg,0,i) + rh.query(flg,i,i+1)*rh.b[flg][i+1] + rh.query(flg,i+1,i+2)*rh.b[flg][i] + rh.query(flg,i+2,n)*rh.b[flg][i+2])%rh.mod_list[flg] X[2].add(v2) # print(i,v0,v1) # print(s)