結果

問題 No.599 回文かい
ユーザー mattu34mattu34
提出日時 2023-04-14 11:59:14
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,222 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 72,440 KB
最終ジャッジ日時 2024-04-18 11:20:35
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
evil_0.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(int(1E+7))
import random

import math

def is_prime(n):
    sqrt_n = math.ceil(math.sqrt(n))
    for i in range(2, sqrt_n):
        if n % i == 0:
            return False
    return True

def RandomMod(l,r):
    while(True):
        res=random.randrange(l,r)
        if is_prime(res):
            return res
dp=[1]*(10**4+1)
vis=[0]*(10**4+1)
def dfs(L,R):
    if R<L:
        return 1
    if vis[L]:
        return dp[L]
    
    l,r=L,R
    while(l<r):
        x1=(s1[l+1]-s1[L]*b1l[l+1-L])%mod1
        x2=(s2[l+1]-s2[L]*b2l[l+1-L])%mod2
        # y1=(s1[R+1]-s1[r]*b1l[R+1-r])%mod1
        # y2=(s2[R+1]-s2[r]*b2l[R+1-r])%mod2
        if x1==y1 and x2==y2:
            dp[L]+=dfs(l+1,r-1)
        l+=1
        r-=1
    vis[L]=1
    return 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%mod1
    b2l[i+1]=b2l[i]*b2%mod2

t1=0
t2=0
for i in range(L):
    t1=(t1*b1+(ord(S[i])-ord("a")+1))%mod1
    t2=(t2*b2+(ord(S[i])-ord("a")+1))%mod2
    s1[i+1]=t1
    s2[i+1]=t2

print(dfs(0,L-1))
0