結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-19 20:16:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 558 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 18,980 KB
最終ジャッジ日時 2024-04-20 20:14:01
合計ジャッジ時間 7,083 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,624 KB
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 32 ms
10,624 KB
testcase_03 AC 32 ms
10,496 KB
testcase_04 AC 30 ms
10,624 KB
testcase_05 AC 34 ms
10,624 KB
testcase_06 AC 30 ms
10,624 KB
testcase_07 AC 30 ms
10,624 KB
testcase_08 AC 29 ms
10,624 KB
testcase_09 AC 31 ms
10,624 KB
testcase_10 AC 40 ms
10,752 KB
testcase_11 AC 39 ms
10,624 KB
testcase_12 AC 66 ms
10,752 KB
testcase_13 AC 87 ms
10,624 KB
testcase_14 TLE -
testcase_15 AC 292 ms
10,880 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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