結果

問題 No.599 回文かい
ユーザー 山本信二山本信二
提出日時 2022-04-07 08:56:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 746 bytes
コンパイル時間 1,217 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 12,840 KB
最終ジャッジ日時 2023-08-18 16:23:18
合計ジャッジ時間 17,975 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,788 KB
testcase_01 AC 14 ms
7,776 KB
testcase_02 AC 14 ms
7,784 KB
testcase_03 AC 14 ms
7,768 KB
testcase_04 AC 22 ms
7,888 KB
testcase_05 AC 20 ms
7,852 KB
testcase_06 AC 23 ms
7,764 KB
testcase_07 AC 25 ms
7,764 KB
testcase_08 AC 23 ms
7,836 KB
testcase_09 AC 21 ms
7,804 KB
testcase_10 AC 3,403 ms
8,272 KB
testcase_11 AC 1,878 ms
8,060 KB
testcase_12 AC 3,727 ms
8,304 KB
testcase_13 AC 2,162 ms
8,072 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7

S = input()
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