結果

問題 No.599 回文かい
ユーザー maspymaspy
提出日時 2020-03-19 12:36:44
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 861 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 79,024 KB
最終ジャッジ日時 2023-08-20 20:46:07
合計ジャッジ時間 4,954 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,316 KB
testcase_01 AC 74 ms
71,244 KB
testcase_02 AC 73 ms
70,980 KB
testcase_03 AC 75 ms
71,032 KB
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 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
evil_0.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10 ** 9 + 7

S = read().rstrip()
N = len(S)


def z_algorithm(S):
    """compute the lengths of common prefix. """
    N = len(S)
    arr = [0] * N
    arr[0] = N
    i, j = 1, 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        arr[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while i + k < N and k + arr[k] < j:
            arr[i + k] = arr[k]
            k += 1
        i += k
        j -= k
    return arr


M = N // 2
dp = [1] * (M + 1)
for n in range(M, -1, -1):
    T = S[n:N - n]
    Z = z_algorithm(T)
    for i in range(1, len(T) // 2 + 1):
        if Z[-i] == i:
            dp[n] += dp[n + i]
    dp[n] %= MOD
print(dp[0])
0