結果
問題 | No.599 回文かい |
ユーザー |
![]() |
提出日時 | 2020-05-25 23:38:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 854 ms / 4,000 ms |
コード長 | 1,518 bytes |
コンパイル時間 | 187 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 84,320 KB |
最終ジャッジ日時 | 2024-10-13 02:22:02 |
合計ジャッジ時間 | 3,866 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
import sysdef SI(): return sys.stdin.readline()[:-1]def LcpByZ(target):# s = input()len_t = len(target)lcp = [-1] * len_ttop = 1 # 右の箱において、左の箱の0に対応する点left = 0 # 左の箱の左端(本当はここでので宣言は不要だけど理解の為)right = 0 # 左の箱の右端lcp[0] = 0while top < len_t:# 箱を右に広げていくwhile top + right < len_t and target[right] == target[top + right]:right += 1# 右の箱左端のlcpを記録lcp[top] = rightleft = 1# 箱の幅が0だったらtopを動かして、このターン終了if right == 0:top += 1continue# lcpを記録しながら箱を左に縮めていく(最初の条件重要)while left + lcp[left] < right and left < right:lcp[top + left] = lcp[left]left += 1# topを右の箱の左端にして、左の箱を0まで戻すtop += leftright -= leftleft = 0 # これも本当は不要return lcpdef main():md=10**9+7s=SI()n=len(s)dp=[0]*(n//2+1)dp[0]=1for i in range(n//2):pre=dp[i]if pre==0:continuelcp=LcpByZ(s[i:n-i])m=(n-2*i)for j in range(1,m//2+1):if lcp[m-j]==j:dp[i+j]=(dp[i+j]+pre)%mddp[n//2]=(dp[n//2]+pre)%md#print(i,lcp,dp)print(dp[-1])main()