結果
問題 | No.2102 [Cherry Alpha *] Conditional Reflection |
ユーザー | roaris |
提出日時 | 2022-10-15 01:50:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,270 bytes |
コンパイル時間 | 357 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 255,540 KB |
最終ジャッジ日時 | 2024-06-26 19:07:02 |
合計ジャッジ時間 | 39,459 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
56,224 KB |
testcase_01 | AC | 46 ms
57,652 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 497 ms
86,364 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 354 ms
83,924 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 584 ms
95,524 KB |
testcase_43 | AC | 579 ms
95,524 KB |
testcase_44 | AC | 587 ms
95,940 KB |
testcase_45 | AC | 577 ms
96,040 KB |
testcase_46 | AC | 611 ms
95,768 KB |
testcase_47 | AC | 545 ms
88,500 KB |
testcase_48 | AC | 538 ms
88,496 KB |
testcase_49 | AC | 537 ms
88,196 KB |
testcase_50 | AC | 539 ms
88,496 KB |
testcase_51 | AC | 541 ms
88,240 KB |
testcase_52 | AC | 366 ms
254,604 KB |
testcase_53 | AC | 362 ms
254,688 KB |
testcase_54 | AC | 387 ms
255,540 KB |
testcase_55 | AC | 509 ms
78,740 KB |
testcase_56 | AC | 506 ms
78,584 KB |
testcase_57 | AC | 510 ms
78,348 KB |
testcase_58 | AC | 518 ms
243,424 KB |
testcase_59 | AC | 699 ms
112,992 KB |
testcase_60 | WA | - |
testcase_61 | AC | 503 ms
78,780 KB |
testcase_62 | AC | 123 ms
78,324 KB |
testcase_63 | AC | 233 ms
78,268 KB |
testcase_64 | AC | 236 ms
78,312 KB |
testcase_65 | AC | 247 ms
78,336 KB |
testcase_66 | AC | 488 ms
78,852 KB |
testcase_67 | AC | 327 ms
79,572 KB |
testcase_68 | AC | 501 ms
78,752 KB |
testcase_69 | AC | 330 ms
79,612 KB |
ソースコード
import sys input = sys.stdin.readline from collections import * import random class RollingHash1: def __init__(self, s): self.base = base1 self.mod = 10**9+7 self.acc = [0] self.power = [1] for i in range(len(s)): self.acc.append((self.acc[-1]*self.base%self.mod+(ord(s[i])-ord('a')))%self.mod) self.power.append(self.power[-1]*self.base%self.mod) def get(self, l, r): return (self.acc[r]-self.acc[l]*self.power[r-l])%self.mod class RollingHash2: def __init__(self, s): self.base = base2 self.mod = 10**9+9 self.acc = [0] self.power = [1] for i in range(len(s)): self.acc.append((self.acc[-1]*self.base%self.mod+(ord(s[i])-ord('a')))%self.mod) self.power.append(self.power[-1]*self.base%self.mod) def get(self, l, r): return (self.acc[r]-self.acc[l]*self.power[r-l])%self.mod N = int(input()) ws = set() base1 = random.randint(2, 10**9+6) base2 = random.randint(2, 10**9+8) for _ in range(N): S = input()[:-1] n = len(S) rh1 = RollingHash1(S) rh2 = RollingHash2(S) h1 = rh1.get(0, n) h2 = rh2.get(0, n) if (h1, h2) in ws: print('Yes') else: for i in range(n-1): nh1 = h1 nh1 -= (ord(S[i])-ord('a'))*rh1.power[n-1-i]%rh1.mod nh1 %= rh1.mod nh1 -= (ord(S[i+1])-ord('a'))*rh1.power[n-2-i]%rh1.mod nh1 %= rh1.mod nh1 += (ord(S[i+1])-ord('a'))*rh1.power[n-1-i]%rh1.mod nh1 %= rh1.mod nh1 += (ord(S[i])-ord('a'))*rh1.power[n-2-i]%rh1.mod nh1 %= rh1.mod nh2 = h2 nh2 -= (ord(S[i])-ord('a'))*rh2.power[n-1-i]%rh2.mod nh2 %= rh2.mod nh2 -= (ord(S[i+1])-ord('a'))*rh2.power[n-2-i]%rh2.mod nh2 %= rh2.mod nh2 += (ord(S[i+1])-ord('a'))*rh2.power[n-1-i]%rh2.mod nh2 %= rh2.mod nh2 += (ord(S[i])-ord('a'))*rh2.power[n-2-i]%rh2.mod nh2 %= rh2.mod if (nh1, nh2) in ws: print('Yes') break else: print('No') ws.add((h1, h2))