結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-08 21:13:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 245 ms / 4,000 ms
コード長 715 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 86,560 KB
実行使用メモリ 83,336 KB
最終ジャッジ日時 2023-09-11 03:28:38
合計ジャッジ時間 4,725 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,528 KB
testcase_01 AC 76 ms
71,268 KB
testcase_02 AC 75 ms
71,412 KB
testcase_03 AC 75 ms
71,364 KB
testcase_04 AC 77 ms
75,212 KB
testcase_05 AC 79 ms
75,712 KB
testcase_06 AC 75 ms
71,348 KB
testcase_07 AC 74 ms
71,280 KB
testcase_08 AC 77 ms
71,396 KB
testcase_09 AC 81 ms
75,768 KB
testcase_10 AC 82 ms
76,000 KB
testcase_11 AC 85 ms
76,132 KB
testcase_12 AC 83 ms
76,176 KB
testcase_13 AC 87 ms
76,336 KB
testcase_14 AC 183 ms
82,952 KB
testcase_15 AC 89 ms
76,412 KB
testcase_16 AC 227 ms
83,336 KB
testcase_17 AC 245 ms
82,888 KB
testcase_18 AC 76 ms
71,384 KB
testcase_19 AC 76 ms
71,300 KB
testcase_20 AC 77 ms
71,472 KB
evil_0.txt AC 465 ms
80,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
S = [ord(c)-97 for c in input()]
#S = [ord("a")]*(10**4)
length = len(S)
mod = 10**9+7

left_kc, right_kc = S[:length//2], S[::-1][:length//2]
S = None
p = 1
for i in range(length//2):
    left_kc[i] = (left_kc[i] * p) % mod
    p = p * 10 % mod

dp = [0]*(length//2+1)


def rec(left):
    count = 1
    left_hash, right_hash = 0, 0
    m = pow(10, left, mod)
    for i in range(left, length//2):
        left_hash = (left_hash + left_kc[i]) % mod
        right_hash = (right_hash * 10 + right_kc[i]*m) % mod
        if left_hash == right_hash:
            count += dp[i+1] or rec(i+1)
            count %= mod

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


print(rec(0))
0