結果
問題 | No.599 回文かい |
ユーザー |
![]() |
提出日時 | 2023-04-14 12:02:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,593 ms / 4,000 ms |
コード長 | 1,253 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 82,332 KB |
実行使用メモリ | 86,208 KB |
最終ジャッジ日時 | 2024-10-10 04:34:31 |
合計ジャッジ時間 | 8,577 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
MOD=10**9+7import syssys.setrecursionlimit(int(1E+7))import randomimport mathdef is_prime(n):sqrt_n = math.ceil(math.sqrt(n))for i in range(2, sqrt_n):if n % i == 0:return Falsereturn Truedef RandomMod(l,r):while(True):res=random.randrange(l,r)if is_prime(res):return resdp=[1]*(10**4+1)vis=[0]*(10**4+1)def dfs(L,R):if R<L:return 1if vis[L]:return dp[L]l,r=L,Rwhile(l<r):x1=(s1[l+1]-s1[L]*b1l[l+1-L])%mod1x2=(s2[l+1]-s2[L]*b2l[l+1-L])%mod2y1=(s1[R+1]-s1[r]*b1l[R+1-r])%mod1y2=(s2[R+1]-s2[r]*b2l[R+1-r])%mod2if x1==y1 and x2==y2:dp[L]+=dfs(l+1,r-1)dp[L]%=MODl+=1r-=1vis[L]=1return dp[L]S=input()L=len(S)mod1=RandomMod(7*10**7,10**9)mod2=RandomMod(7*10**7,10**9)b1=random.randrange(100,200)b2=random.randrange(100,200)s1=[0]*(L+1)s2=[0]*(L+1)b1l=[1]*(L+1)b2l=[1]*(L+1)for i in range(L):b1l[i+1]=b1l[i]*b1%mod1b2l[i+1]=b2l[i]*b2%mod2t1=0t2=0for i in range(L):t1=(t1*b1+(ord(S[i])-ord("a")+1))%mod1t2=(t2*b2+(ord(S[i])-ord("a")+1))%mod2s1[i+1]=t1s2[i+1]=t2print(dfs(0,L-1))