結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-08 21:09:37
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 760 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 284,208 KB
最終ジャッジ日時 2023-09-11 03:22:24
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,244 KB
testcase_01 AC 73 ms
71,220 KB
testcase_02 AC 74 ms
71,228 KB
testcase_03 AC 73 ms
71,120 KB
testcase_04 AC 77 ms
75,624 KB
testcase_05 AC 80 ms
76,064 KB
testcase_06 AC 74 ms
71,164 KB
testcase_07 AC 73 ms
71,216 KB
testcase_08 AC 76 ms
71,060 KB
testcase_09 AC 79 ms
76,000 KB
testcase_10 AC 78 ms
76,088 KB
testcase_11 AC 78 ms
75,976 KB
testcase_12 AC 81 ms
76,172 KB
testcase_13 AC 83 ms
76,072 KB
testcase_14 AC 354 ms
226,164 KB
testcase_15 AC 94 ms
76,356 KB
testcase_16 AC 413 ms
248,508 KB
testcase_17 MLE -
testcase_18 AC 77 ms
71,124 KB
testcase_19 AC 77 ms
71,068 KB
testcase_20 AC 77 ms
71,404 KB
evil_0.txt AC 629 ms
147,632 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//2+1)


def rec(left):
    count = 1
    left_hash, right_hash = 0, 0
    m = pow(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