結果

問題 No.599 回文かい
ユーザー htkbhtkb
提出日時 2019-02-08 21:09:00
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 758 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 289,044 KB
最終ジャッジ日時 2023-09-11 03:21:19
合計ジャッジ時間 6,559 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,144 KB
testcase_01 AC 77 ms
71,024 KB
testcase_02 AC 75 ms
71,212 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
evil_0.txt RE -
権限があれば一括ダウンロードができます

ソースコード

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)


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