結果

問題 No.599 回文かい
ユーザー mattu34mattu34
提出日時 2023-04-15 09:19:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,188 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 82,620 KB
実行使用メモリ 117,680 KB
最終ジャッジ日時 2024-04-19 05:24:33
合計ジャッジ時間 6,336 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import random
 
def isprime(n):
	if n == 1:
		return False
	for i in range(2, int(n**0.5)+1):
		if n % i == 0:
			return False
	return True

def RandomMod(l,r):
	ret = random.randrange(l, r)
	while not isprime(ret):
		ret = random.randrange(l, r)
	return ret

s=input()
N=len(s)
memo=[1]*(N+1)
vis=[0]*(N+1)
def dfs(L,R):
    if vis[L]!=0:
        return memo[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]-s1[r-1]*b1l[R-r+1])%mod1
        y2=(s2[R]-s2[r-1]*b2l[R-r+1])%mod2
        if x1==y1 and x2==y2:
            memo[L]+=dfs(l+1,r-1)
        l+=1
        r-=1
    return memo[L]
    
 
mod1 = RandomMod(7*10**8, 10**9)
b1 = random.randrange(100, 200)
mod2 = RandomMod(7*10**8, 10**9)
b2 = random.randrange(100, 200)

b1l = [0] * (N+1)
b1l[0] = 1
for i in range(N):
	b1l[i+1] = b1l[i] * b1 % mod1
 
b2l = [0] * (N+1)
b2l[0] = 1
for i in range(N):
	b2l[i+1] = b2l[i] * b2 % mod2
 
s1 = [0] * (N + 1)
s2 = [0] * (N + 1)
t1 = 0
t2 = 0

for i in range(N):
	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,N))
0