結果
| 問題 |
No.2102 [Cherry Alpha *] Conditional Reflection
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2022-10-14 22:45:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 581 ms / 3,000 ms |
| コード長 | 840 bytes |
| コンパイル時間 | 456 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 265,916 KB |
| 最終ジャッジ日時 | 2024-06-26 16:26:51 |
| 合計ジャッジ時間 | 33,374 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 70 |
ソースコード
import sys
input = sys.stdin.readline
N=int(input())
S=[list(input().strip()) for i in range(N)]
# Rolling Hash
LEN=len(S)
p=26 # 文字の種類
mod=(1<<50)+1 # Hashがぶつからない, pと互いに素な数を適当に指定
MAX=0
for s in S:
MAX=max(MAX,len(s))
CHECKLEN=[set() for i in range(MAX+1)]
POWP=[1]
for i in range(10**6+1):
POWP.append(POWP[-1]*p%mod)
for s in S:
LEN=len(s)
score=0
for i in range(LEN):
score=(score+(ord(s[i])-97)*POWP[i])%mod
if score in CHECKLEN[LEN]:
print("Yes")
else:
print("No")
CHECKLEN[LEN].add(score)
for i in range(LEN-1):
score2=(score-(ord(s[i])-97)*POWP[i]-(ord(s[i+1])-97)*POWP[i+1]+(ord(s[i+1])-97)*POWP[i]+(ord(s[i])-97)*POWP[i+1])%mod
CHECKLEN[LEN].add(score2)
titia