結果
問題 | No.2102 [Cherry Alpha *] Conditional Reflection |
ユーザー | flygon |
提出日時 | 2022-10-15 14:34:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 513 ms / 3,000 ms |
コード長 | 1,507 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 129,888 KB |
最終ジャッジ日時 | 2024-06-26 19:49:42 |
合計ジャッジ時間 | 27,371 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,784 KB |
testcase_01 | AC | 39 ms
54,816 KB |
testcase_02 | AC | 339 ms
105,372 KB |
testcase_03 | AC | 390 ms
111,800 KB |
testcase_04 | AC | 375 ms
106,768 KB |
testcase_05 | AC | 318 ms
99,936 KB |
testcase_06 | AC | 369 ms
108,256 KB |
testcase_07 | AC | 240 ms
93,676 KB |
testcase_08 | AC | 231 ms
88,804 KB |
testcase_09 | AC | 320 ms
101,376 KB |
testcase_10 | AC | 272 ms
92,884 KB |
testcase_11 | AC | 205 ms
87,996 KB |
testcase_12 | AC | 313 ms
99,712 KB |
testcase_13 | AC | 390 ms
109,784 KB |
testcase_14 | AC | 333 ms
101,448 KB |
testcase_15 | AC | 401 ms
111,464 KB |
testcase_16 | AC | 467 ms
119,864 KB |
testcase_17 | AC | 191 ms
88,720 KB |
testcase_18 | AC | 280 ms
99,352 KB |
testcase_19 | AC | 266 ms
94,764 KB |
testcase_20 | AC | 405 ms
114,444 KB |
testcase_21 | AC | 303 ms
95,208 KB |
testcase_22 | AC | 506 ms
124,248 KB |
testcase_23 | AC | 513 ms
124,284 KB |
testcase_24 | AC | 499 ms
122,920 KB |
testcase_25 | AC | 494 ms
122,404 KB |
testcase_26 | AC | 499 ms
124,012 KB |
testcase_27 | AC | 494 ms
125,148 KB |
testcase_28 | AC | 496 ms
126,788 KB |
testcase_29 | AC | 497 ms
124,636 KB |
testcase_30 | AC | 483 ms
125,552 KB |
testcase_31 | AC | 500 ms
124,140 KB |
testcase_32 | AC | 486 ms
122,908 KB |
testcase_33 | AC | 501 ms
125,620 KB |
testcase_34 | AC | 505 ms
124,320 KB |
testcase_35 | AC | 495 ms
125,128 KB |
testcase_36 | AC | 500 ms
122,452 KB |
testcase_37 | AC | 500 ms
124,472 KB |
testcase_38 | AC | 501 ms
124,340 KB |
testcase_39 | AC | 496 ms
124,328 KB |
testcase_40 | AC | 510 ms
124,884 KB |
testcase_41 | AC | 490 ms
122,500 KB |
testcase_42 | AC | 328 ms
104,628 KB |
testcase_43 | AC | 332 ms
104,436 KB |
testcase_44 | AC | 333 ms
104,356 KB |
testcase_45 | AC | 326 ms
104,400 KB |
testcase_46 | AC | 337 ms
104,532 KB |
testcase_47 | AC | 275 ms
96,312 KB |
testcase_48 | AC | 273 ms
96,316 KB |
testcase_49 | AC | 272 ms
96,320 KB |
testcase_50 | AC | 265 ms
96,564 KB |
testcase_51 | AC | 273 ms
96,436 KB |
testcase_52 | AC | 182 ms
117,096 KB |
testcase_53 | AC | 181 ms
116,928 KB |
testcase_54 | AC | 179 ms
117,084 KB |
testcase_55 | AC | 159 ms
84,884 KB |
testcase_56 | AC | 161 ms
85,124 KB |
testcase_57 | AC | 159 ms
84,952 KB |
testcase_58 | AC | 167 ms
101,640 KB |
testcase_59 | AC | 472 ms
129,888 KB |
testcase_60 | AC | 206 ms
88,512 KB |
testcase_61 | AC | 161 ms
85,012 KB |
testcase_62 | AC | 95 ms
77,876 KB |
testcase_63 | AC | 192 ms
89,420 KB |
testcase_64 | AC | 194 ms
89,640 KB |
testcase_65 | AC | 197 ms
89,420 KB |
testcase_66 | AC | 157 ms
85,524 KB |
testcase_67 | AC | 335 ms
101,304 KB |
testcase_68 | AC | 151 ms
84,984 KB |
testcase_69 | AC | 326 ms
101,412 KB |
ソースコード
class Hasher(): def __init__(self, length, base, mod): self.length=length self.base=base self.mod=mod self.power=pw=[1]*length for i in range(1,length): pw[i]=(base*pw[i-1])%mod def __repr__(self): return "length: {}\nbase: {}\nmod: {}".format(self.length, self.base, self.mod) def encode(self, S): code=0; N=len(S) for i in range(N): #code+=ord(S[i])*self.power[N-1-i]%self.mod code+=S[i]*self.power[N-1-i]%self.mod return code%self.mod def decode(self, S): pass def hashing(a,b): return a*q+b from random import randint n = int(input()) s = [""]*n L = 0 for i in range(n): s[i] = [ord(a) - ord("a")+ 1 for a in input()] L = max(L, len(s[i])) p = 10**9+7 beta = randint(2, p-1) q = 10**9+9 gamma = randint(2, q-1) Bp = [1]*L Bq= [1]*L Hp = Hasher(L, beta, p) Hq = Hasher(L, gamma, q) for j in range(1, L): Bp[j] = Bp[j-1]*beta%p Bq[j] = Bq[j-1]*gamma%q for j in range(L): Bp[j] *= beta-1 Bq[j] *= gamma-1 Bp[j] %= p Bq[j] %= q E = set() ans = [0]*n for i in range(n): hp = Hp.encode(s[i]) hq = Hq.encode(s[i]) h = hashing(hp, hq) if h in E: ans[i] = 1 continue lensi = len(s[i]) for j in range(lensi-1): kp = (hp + Bp[lensi-j-2]*(s[i][j+1] - s[i][j]))%p kq = (hq + Bq[lensi-j-2]*(s[i][j+1] - s[i][j]))%q if hashing(kp, kq) in E: ans[i] = 1 E.add(h) for i in ans: print('Yes') if i else print('No')