結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-19 20:16:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 215 ms / 4,000 ms
コード長 558 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 76,928 KB
最終ジャッジ日時 2024-04-20 20:15:47
合計ジャッジ時間 3,090 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
51,712 KB
testcase_01 AC 46 ms
52,224 KB
testcase_02 AC 45 ms
52,224 KB
testcase_03 AC 46 ms
52,316 KB
testcase_04 AC 51 ms
58,240 KB
testcase_05 AC 51 ms
59,136 KB
testcase_06 AC 45 ms
52,096 KB
testcase_07 AC 42 ms
52,096 KB
testcase_08 AC 49 ms
52,224 KB
testcase_09 AC 48 ms
58,880 KB
testcase_10 AC 50 ms
59,904 KB
testcase_11 AC 51 ms
59,648 KB
testcase_12 AC 52 ms
60,160 KB
testcase_13 AC 53 ms
60,544 KB
testcase_14 AC 156 ms
76,672 KB
testcase_15 AC 66 ms
62,464 KB
testcase_16 AC 203 ms
76,800 KB
testcase_17 AC 215 ms
76,928 KB
testcase_18 AC 42 ms
52,096 KB
testcase_19 AC 42 ms
52,352 KB
testcase_20 AC 43 ms
52,392 KB
evil_0.txt AC 563 ms
78,720 KB
権限があれば一括ダウンロードができます

ソースコード

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