結果
| 問題 | No.599 回文かい |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2026-07-29 01:15:14 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 892 bytes |
| 記録 | |
| コンパイル時間 | 230 ms |
| コンパイル使用メモリ | 96,104 KB |
| 実行使用メモリ | 90,704 KB |
| 最終ジャッジ日時 | 2026-07-29 01:15:21 |
| 合計ジャッジ時間 | 4,308 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 6 RE * 4 |
ソースコード
from functools import cache
def rolling_hash(s: str):
"""[l, r] のハッシュを返す関数を返す"""
mod = 998244353
p = 1009
n = len(s)
t = [ord(c) for c in s]
a = [0] * n
b = [0] * n
a[0] = t[0]
b[0] = 1
for i in range(1, n):
a[i] = (a[i-1] * p + t[i]) % mod
b[i] = (p * b[i-1]) % mod
# [l, r] のハッシュ値
def f(l: int, r: int) -> int:
assert 0 <= l <= r < n
h = a[r]
if l > 0:
h -= a[l-1] * b[r-l+1]
h %= mod
return h
return f
S = input()
h = rolling_hash(S)
@cache
def f(l, r):
if l > r:
return 1
res = 1 # ひとつの単語は回文
lo = l
hi = r
while lo < hi:
if h(l, lo) == h(hi, r):
res += f(lo+1, hi-1)
lo += 1
hi -= 1
return res
ans = f(0, len(S)-1)
print(ans)
norioc