結果

問題 No.599 回文かい
ユーザー 前田悠真
提出日時 2025-08-09 14:16:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 4,000 ms
コード長 508 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 66,200 KB
最終ジャッジ日時 2025-08-09 14:16:56
合計ジャッジ時間 2,530 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(map(lambda x:ord(x), input()))

n = len(S)
if n==1:
  print(1)
  exit()
mod = 10**9+7

p = 1007
mod2 = mod


dp = [0]*(n//2+1)
dp[0] = 1
ans = 0
# print(SR)
pp = pow(p, mod2-2, mod2)
for i in range(n//2):
  left = 0
  right = 0
  p_ = 1
  t = dp[i]
  ans += t
  ans %= mod
  for j in range(i, n//2):
    left += p_*S[j]
    left %= mod
    right = right*p+S[~j]
    right %= mod
    p_ *= p
    p_ %= mod
    if left==right:
      dp[j+1] += t
      dp[j+1] %= mod

ans += dp[-1]


print(ans%mod)


0