結果

問題 No.599 回文かい
ユーザー htkb
提出日時 2019-02-19 20:16:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 558 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-10-12 18:16:00
合計ジャッジ時間 11,734 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 TLE * 2 -- * 5
権限があれば一括ダウンロードができます

ソースコード

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