結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-04 19:10:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 835 bytes |
| コンパイル時間 | 386 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 207,360 KB |
| 最終ジャッジ日時 | 2024-09-15 06:03:09 |
| 合計ジャッジ時間 | 4,969 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 RE * 18 |
ソースコード
import sys
input = sys.stdin.readline
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)))