結果

問題 No.599 回文かい
ユーザー mkawa2mkawa2
提出日時 2020-05-25 23:38:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 868 ms / 4,000 ms
コード長 1,518 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 86,608 KB
実行使用メモリ 85,268 KB
最終ジャッジ日時 2023-08-03 04:34:21
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,088 KB
testcase_01 AC 64 ms
71,220 KB
testcase_02 AC 67 ms
71,228 KB
testcase_03 AC 66 ms
71,008 KB
testcase_04 AC 73 ms
75,680 KB
testcase_05 AC 78 ms
75,556 KB
testcase_06 AC 65 ms
71,312 KB
testcase_07 AC 68 ms
75,228 KB
testcase_08 AC 70 ms
75,056 KB
testcase_09 AC 72 ms
75,648 KB
testcase_10 AC 73 ms
75,548 KB
testcase_11 AC 74 ms
75,488 KB
testcase_12 AC 73 ms
75,248 KB
testcase_13 AC 80 ms
76,072 KB
testcase_14 AC 437 ms
83,612 KB
testcase_15 AC 95 ms
76,424 KB
testcase_16 AC 762 ms
83,740 KB
testcase_17 AC 868 ms
85,268 KB
testcase_18 AC 68 ms
75,188 KB
testcase_19 AC 70 ms
75,076 KB
testcase_20 AC 71 ms
75,156 KB
evil_0.txt AC 199 ms
78,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def SI(): return sys.stdin.readline()[:-1]

def LcpByZ(target):
    # s = input()
    len_t = len(target)
    lcp = [-1] * len_t
    top = 1  # 右の箱において、左の箱の0に対応する点
    left = 0  # 左の箱の左端(本当はここでので宣言は不要だけど理解の為)
    right = 0  # 左の箱の右端
    lcp[0] = 0
    while top < len_t:
        # 箱を右に広げていく
        while top + right < len_t and target[right] == target[top + right]:
            right += 1
        # 右の箱左端のlcpを記録
        lcp[top] = right
        left = 1
        # 箱の幅が0だったらtopを動かして、このターン終了
        if right == 0:
            top += 1
            continue
        # lcpを記録しながら箱を左に縮めていく(最初の条件重要)
        while left + lcp[left] < right and left < right:
            lcp[top + left] = lcp[left]
            left += 1
        # topを右の箱の左端にして、左の箱を0まで戻す
        top += left
        right -= left
        left = 0  # これも本当は不要
    return lcp

def main():
    md=10**9+7
    s=SI()
    n=len(s)
    dp=[0]*(n//2+1)
    dp[0]=1
    for i in range(n//2):
        pre=dp[i]
        if pre==0:continue
        lcp=LcpByZ(s[i:n-i])
        m=(n-2*i)
        for j in range(1,m//2+1):
            if lcp[m-j]==j:
                dp[i+j]=(dp[i+j]+pre)%md
        dp[n//2]=(dp[n//2]+pre)%md
        #print(i,lcp,dp)
    print(dp[-1])

main()
0