結果

問題 No.599 回文かい
ユーザー htkb
提出日時 2019-02-19 20:16:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 194 ms / 4,000 ms
コード長 558 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-10-12 18:17:31
合計ジャッジ時間 2,655 ms
ジャッジサーバーID
(参考情報)
judge4 / judge
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

s = list(map(ord, input()))
length = len(s) // 2
s, s_rev = s[:length], s[::-1][:length]
mod = 10**9+7
base = 10
dp = [0]*(length+1)


def rec(i):
    hash_l, hash_r, c_base = 0, 0, 1
    count = 1

    for j in range(i, length):
        hash_l = (hash_l * base + s[j]) % mod
        hash_r = (hash_r + s_rev[j] * c_base) % mod
        c_base = c_base * base % mod
        if hash_l == hash_r:
            count += dp[j+1] or rec(j+1)
            count %= mod

    dp[i] = count % mod
    return dp[i]


print(rec(0))
0