結果

問題 No.599 回文かい
ユーザー maspymaspy
提出日時 2020-03-19 12:39:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 745 ms / 4,000 ms
コード長 893 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 80,896 KB
最終ジャッジ日時 2024-05-08 03:10:39
合計ジャッジ時間 4,800 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,840 KB
testcase_01 AC 39 ms
52,096 KB
testcase_02 AC 39 ms
51,840 KB
testcase_03 AC 40 ms
52,096 KB
testcase_04 AC 53 ms
63,104 KB
testcase_05 AC 52 ms
62,080 KB
testcase_06 AC 59 ms
65,536 KB
testcase_07 AC 58 ms
64,384 KB
testcase_08 AC 57 ms
64,000 KB
testcase_09 AC 53 ms
62,592 KB
testcase_10 AC 178 ms
76,416 KB
testcase_11 AC 146 ms
76,160 KB
testcase_12 AC 204 ms
76,448 KB
testcase_13 AC 148 ms
76,288 KB
testcase_14 AC 413 ms
77,532 KB
testcase_15 AC 341 ms
77,056 KB
testcase_16 AC 660 ms
79,744 KB
testcase_17 AC 745 ms
80,896 KB
testcase_18 AC 43 ms
57,344 KB
testcase_19 AC 44 ms
57,984 KB
testcase_20 AC 44 ms
57,600 KB
evil_0.txt AC 249 ms
76,672 KB
権限があれば一括ダウンロードができます

ソースコード

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]
    if not T:
        continue
    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