結果

問題 No.599 回文かい
ユーザー brthyyjpbrthyyjp
提出日時 2021-11-25 15:31:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,774 ms / 4,000 ms
コード長 687 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 86,792 KB
実行使用メモリ 100,280 KB
最終ジャッジ日時 2023-09-10 15:50:17
合計ジャッジ時間 8,729 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,152 KB
testcase_01 AC 74 ms
71,004 KB
testcase_02 AC 72 ms
71,280 KB
testcase_03 AC 73 ms
71,068 KB
testcase_04 AC 84 ms
75,956 KB
testcase_05 AC 85 ms
75,712 KB
testcase_06 AC 96 ms
76,572 KB
testcase_07 AC 91 ms
76,128 KB
testcase_08 AC 87 ms
75,984 KB
testcase_09 AC 84 ms
76,148 KB
testcase_10 AC 279 ms
79,000 KB
testcase_11 AC 207 ms
78,284 KB
testcase_12 AC 324 ms
79,636 KB
testcase_13 AC 226 ms
78,276 KB
testcase_14 AC 527 ms
82,108 KB
testcase_15 AC 511 ms
82,908 KB
testcase_16 AC 1,538 ms
95,628 KB
testcase_17 AC 1,774 ms
100,280 KB
testcase_18 AC 79 ms
75,388 KB
testcase_19 AC 77 ms
74,876 KB
testcase_20 AC 78 ms
75,412 KB
evil_0.txt AC 366 ms
80,796 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

s = str(input())
n = len(s)
mod = 10**9+7
dp = [1]*(n//2+1)
for i in reversed(range(n)):
    if i >= n-i:
        continue
    t = s[i:n-i]
    Z = z_algorithm(t)
    for j in range(1, len(t)//2+1):
        if Z[len(t)-j] == j:
            dp[i] += dp[i+j]
            dp[j] %= mod
#print(dp)
print(dp[0]%mod)
0