結果
問題 | No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに |
ユーザー |
![]() |
提出日時 | 2022-10-15 01:50:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,270 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 115,740 KB |
最終ジャッジ日時 | 2024-06-26 19:09:47 |
合計ジャッジ時間 | 62,426 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 42 |
ソースコード
import sysinput = sys.stdin.readlinefrom collections import *import randomclass RollingHash1:def __init__(self, s):self.base = base1self.mod = 10**9+7self.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.modclass RollingHash2:def __init__(self, s):self.base = base2self.mod = 10**9+9self.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.modN = 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 = h1nh1 -= (ord(S[i])-ord('a'))*rh1.power[n-1-i]%rh1.modnh1 %= rh1.modnh1 -= (ord(S[i+1])-ord('a'))*rh1.power[n-2-i]%rh1.modnh1 %= rh1.modnh1 += (ord(S[i+1])-ord('a'))*rh1.power[n-1-i]%rh1.modnh1 %= rh1.modnh1 += (ord(S[i])-ord('a'))*rh1.power[n-2-i]%rh1.modnh1 %= rh1.modnh2 = h2nh2 -= (ord(S[i])-ord('a'))*rh2.power[n-1-i]%rh2.modnh2 %= rh2.modnh2 -= (ord(S[i+1])-ord('a'))*rh2.power[n-2-i]%rh2.modnh2 %= rh2.modnh2 += (ord(S[i+1])-ord('a'))*rh2.power[n-1-i]%rh2.modnh2 %= rh2.modnh2 += (ord(S[i])-ord('a'))*rh2.power[n-2-i]%rh2.modnh2 %= rh2.modif (nh1, nh2) in ws:print('Yes')breakelse:print('No')ws.add((h1, h2))