結果
| 問題 | No.599 回文かい |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-07 08:56:52 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 746 bytes |
| 記録 | |
| コンパイル時間 | 490 ms |
| コンパイル使用メモリ | 20,576 KB |
| 実行使用メモリ | 30,460 KB |
| 最終ジャッジ日時 | 2026-05-22 03:40:53 |
| 合計ジャッジ時間 | 24,816 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 TLE * 2 -- * 5 |
ソースコード
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])