結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-19 20:16:55
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 247 ms / 4,000 ms
コード長 558 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 80,504 KB
最終ジャッジ日時 2023-08-02 20:07:04
合計ジャッジ時間 4,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,936 KB
testcase_01 AC 74 ms
71,088 KB
testcase_02 AC 74 ms
71,020 KB
testcase_03 AC 73 ms
71,176 KB
testcase_04 AC 78 ms
75,116 KB
testcase_05 AC 83 ms
75,932 KB
testcase_06 AC 79 ms
71,096 KB
testcase_07 AC 78 ms
71,252 KB
testcase_08 AC 74 ms
71,100 KB
testcase_09 AC 82 ms
75,724 KB
testcase_10 AC 98 ms
75,452 KB
testcase_11 AC 80 ms
75,452 KB
testcase_12 AC 81 ms
75,540 KB
testcase_13 AC 82 ms
75,604 KB
testcase_14 AC 188 ms
80,232 KB
testcase_15 AC 86 ms
76,080 KB
testcase_16 AC 228 ms
80,216 KB
testcase_17 AC 247 ms
80,504 KB
testcase_18 AC 74 ms
71,112 KB
testcase_19 AC 74 ms
71,200 KB
testcase_20 AC 72 ms
71,064 KB
evil_0.txt AC 573 ms
80,048 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