結果

問題 No.599 回文かい
ユーザー ayaoniayaoni
提出日時 2021-05-03 13:10:06
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 269 ms / 4,000 ms
コード長 1,113 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 76,896 KB
最終ジャッジ日時 2023-09-29 08:37:32
合計ジャッジ時間 4,307 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,448 KB
testcase_01 AC 75 ms
71,316 KB
testcase_02 AC 73 ms
71,096 KB
testcase_03 AC 74 ms
71,468 KB
testcase_04 AC 83 ms
76,272 KB
testcase_05 AC 84 ms
76,188 KB
testcase_06 AC 85 ms
76,368 KB
testcase_07 AC 86 ms
76,280 KB
testcase_08 AC 87 ms
76,136 KB
testcase_09 AC 89 ms
76,252 KB
testcase_10 AC 165 ms
76,896 KB
testcase_11 AC 137 ms
76,768 KB
testcase_12 AC 174 ms
76,644 KB
testcase_13 AC 143 ms
76,780 KB
testcase_14 AC 212 ms
76,564 KB
testcase_15 AC 229 ms
76,780 KB
testcase_16 AC 247 ms
76,892 KB
testcase_17 AC 269 ms
76,704 KB
testcase_18 AC 77 ms
75,452 KB
testcase_19 AC 81 ms
75,364 KB
testcase_20 AC 79 ms
75,320 KB
evil_0.txt AC 189 ms
76,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


S = S()
N = len(S)
if N % 2 == 1:
    S = S[:N//2]+S[N//2+1:]
    N -= 1

ord_S = [ord(s) for s in S]
mod = 10**9+7
r = 1234

A = [ord_S[0]]
for i in range(1,N):
    A.append((A[-1]*r+ord_S[i]) % mod)

power_r = [1]
for _ in range(N):
    power_r.append((power_r[-1]*r) % mod)


def RH(i,j):  # S[i:j+1]のローリングハッシュ
    if i == 0:
        return A[j]
    else:
        return (A[j]-A[i-1]*power_r[j-i+1]) % mod


dp = [0]*(N//2+1)  # dp[i] = S[i:N-i]に対する答え
dp[-1] = 1
for i in range(N//2-1,-1,-1):
    x = 1
    for j in range(i,N//2):
        if RH(i,j) == RH(N-1-j,N-1-i):
            x += dp[j+1]
            x %= mod
    dp[i] = x

ans = dp[0]
print(ans)
0