結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-08 21:04:06
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 714 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 283,072 KB
最終ジャッジ日時 2023-09-11 03:03:18
合計ジャッジ時間 6,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,184 KB
testcase_01 AC 78 ms
71,184 KB
testcase_02 AC 79 ms
70,872 KB
testcase_03 AC 78 ms
71,304 KB
testcase_04 AC 84 ms
75,636 KB
testcase_05 AC 82 ms
75,728 KB
testcase_06 AC 77 ms
71,316 KB
testcase_07 AC 79 ms
71,068 KB
testcase_08 AC 77 ms
71,276 KB
testcase_09 AC 83 ms
75,632 KB
testcase_10 AC 83 ms
76,068 KB
testcase_11 AC 85 ms
75,776 KB
testcase_12 AC 86 ms
75,932 KB
testcase_13 AC 88 ms
76,200 KB
testcase_14 AC 430 ms
240,444 KB
testcase_15 AC 106 ms
84,632 KB
testcase_16 AC 470 ms
252,328 KB
testcase_17 MLE -
testcase_18 AC 79 ms
71,280 KB
testcase_19 AC 77 ms
71,356 KB
testcase_20 AC 75 ms
71,204 KB
evil_0.txt AC 638 ms
147,664 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]
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)

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


print(rec(0))
0