結果

問題 No.599 回文かい
ユーザー roarisroaris
提出日時 2020-12-04 19:11:39
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 867 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 309,956 KB
最終ジャッジ日時 2023-10-13 08:55:03
合計ジャッジ時間 7,690 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,676 KB
testcase_01 AC 89 ms
71,408 KB
testcase_02 AC 89 ms
71,680 KB
testcase_03 AC 89 ms
71,424 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 MLE -
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
input = sys.stdin.readline
sys.setrecursionlimit(10**4+10)
from collections import *

def z_algo(s):
    c = 0
    n = len(s)
    z = [0]*n
    
    for i in range(1, n):
        l = i-c
        
        if i+z[l]<c+z[c]:
            z[i] = z[l]
        else:
            j = max(0, c+z[c]-i)
            
            while i+j<n and s[j]==s[i+j]:
                j += 1
            
            z[i] = j
            c = i
    
    z[0] = n
    return z

def f(l, r):
    t = s[l:r]
    
    if memo[t]!=-1:
        return memo[t]
    
    z = z_algo(t)
    res = 1
    
    for i in range(len(t)-1, -1, -1):
        com = len(t)-i
        
        if z[i]==com and 2*com<=r-l:
            res += f(l+com, r-com)
            res %= MOD
    
    memo[t] = res
    return res

s = input()[:-1]
memo = defaultdict(lambda: -1)
MOD = 10**9+7
print(f(0, len(s)))
0