結果

問題 No.599 回文かい
ユーザー convexineqconvexineq
提出日時 2021-02-14 01:33:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 610 ms / 4,000 ms
コード長 674 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 83,504 KB
最終ジャッジ日時 2023-09-28 11:01:07
合計ジャッジ時間 7,018 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,360 KB
testcase_01 AC 74 ms
71,160 KB
testcase_02 AC 74 ms
71,332 KB
testcase_03 AC 71 ms
71,308 KB
testcase_04 AC 87 ms
76,156 KB
testcase_05 AC 87 ms
76,264 KB
testcase_06 AC 98 ms
75,904 KB
testcase_07 AC 90 ms
76,340 KB
testcase_08 AC 92 ms
76,148 KB
testcase_09 AC 91 ms
75,864 KB
testcase_10 AC 271 ms
79,208 KB
testcase_11 AC 205 ms
78,068 KB
testcase_12 AC 303 ms
79,340 KB
testcase_13 AC 221 ms
78,208 KB
testcase_14 AC 534 ms
81,884 KB
testcase_15 AC 486 ms
81,988 KB
testcase_16 AC 545 ms
82,520 KB
testcase_17 AC 610 ms
83,504 KB
testcase_18 AC 76 ms
75,304 KB
testcase_19 AC 75 ms
75,504 KB
testcase_20 AC 75 ms
75,368 KB
evil_0.txt AC 397 ms
80,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Z_algorithm(s):
    n = len(s)
    z = [0]*n
    z[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and s[j] == s[i+j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+z[k] < j:
            z[i+k] = z[k]
            k += 1
        i += k
        j -= k
    return z

MOD = 10**9+7
s = input()
if len(s)%2==0:
    s = s[:len(s)//2]+"*"+s[len(s)//2:]
n = len(s)
v = (n-1)//2
dp = [1]*(v+1)
for i in range(v+1)[::-1]:
    z = Z_algorithm(s[i:n-i])
    for k in range(1,v-i+1):
        if z[n-2*i-k] == k:
            dp[i] += dp[i+k]
    dp[i] %= MOD
print(dp[0]%MOD)
0