結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-08 21:07:01
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 749 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 284,680 KB
最終ジャッジ日時 2023-09-11 03:18:55
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,504 KB
testcase_01 AC 76 ms
71,176 KB
testcase_02 AC 76 ms
71,216 KB
testcase_03 AC 75 ms
71,168 KB
testcase_04 AC 80 ms
75,548 KB
testcase_05 AC 85 ms
75,776 KB
testcase_06 AC 77 ms
71,348 KB
testcase_07 AC 80 ms
71,348 KB
testcase_08 AC 78 ms
71,352 KB
testcase_09 AC 82 ms
75,828 KB
testcase_10 AC 82 ms
75,972 KB
testcase_11 AC 82 ms
75,792 KB
testcase_12 AC 83 ms
76,156 KB
testcase_13 AC 89 ms
75,972 KB
testcase_14 AC 429 ms
240,188 KB
testcase_15 AC 106 ms
84,684 KB
testcase_16 AC 480 ms
253,124 KB
testcase_17 MLE -
testcase_18 AC 76 ms
71,060 KB
testcase_19 AC 78 ms
71,072 KB
testcase_20 AC 78 ms
71,252 KB
evil_0.txt AC 658 ms
145,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
S = [ord(c) 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


def rec(left):
    count = 1
    left_hash, right_hash = 0, 0
    m = 10**left % mod
    for i, (lc, rc) in enumerate(zip(left_kc[left:length//2], right_kc[left:length//2]), start=left):
        left_hash = (left_hash + lc) % mod
        right_hash = (right_hash * 10 + rc*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