結果

問題 No.599 回文かい
ユーザー mattu34mattu34
提出日時 2023-04-14 11:59:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 89,224 KB
最終ジャッジ日時 2024-04-18 11:21:21
合計ジャッジ時間 10,293 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,848 KB
testcase_01 AC 47 ms
60,612 KB
testcase_02 AC 40 ms
61,124 KB
testcase_03 AC 42 ms
60,212 KB
testcase_04 AC 43 ms
62,148 KB
testcase_05 WA -
testcase_06 AC 42 ms
60,276 KB
testcase_07 AC 42 ms
60,776 KB
testcase_08 AC 45 ms
62,016 KB
testcase_09 WA -
testcase_10 AC 47 ms
64,816 KB
testcase_11 AC 48 ms
63,696 KB
testcase_12 AC 47 ms
64,528 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 TLE -
testcase_18 AC 41 ms
60,776 KB
testcase_19 WA -
testcase_20 WA -
evil_0.txt WA -
権限があれば一括ダウンロードができます

ソースコード

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:
            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