結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:30:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 853 bytes |
| コンパイル時間 | 384 ms |
| コンパイル使用メモリ | 81,696 KB |
| 実行使用メモリ | 65,944 KB |
| 最終ジャッジ日時 | 2025-04-15 23:31:38 |
| 合計ジャッジ時間 | 2,345 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 18 |
ソースコード
MOD = 10**9 + 7
S = input().strip()
n = len(S)
if n == 0:
print(0)
exit()
# Compute the failure function using KMP algorithm
f = [0] * n
for i in range(1, n):
j = f[i-1]
while j > 0 and S[i] != S[j]:
j = f[j-1]
if S[i] == S[j]:
j += 1
f[i] = j
# Initialize dp array where dp[i] represents the number of valid splits for the first i characters
dp = [0] * (n + 1)
dp[0] = 0 # empty string has no valid splits
for i in range(1, n + 1):
dp[i] = 1 # split into one part is always valid
# Check all possible l's from the failure function chain
j = f[i-1] if i-1 >= 0 else 0
while j > 0:
if j <= i // 2:
dp[i] += dp[i - 2 * j]
dp[i] %= MOD
# Move to the next possible l in the chain
j = f[j-1] if j-1 >= 0 else 0
dp[i] %= MOD
print(dp[n] % MOD)
lam6er