結果

問題 No.599 回文かい
ユーザー ayaoniayaoni
提出日時 2021-05-03 10:17:45
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,035 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 838,276 KB
最終ジャッジ日時 2023-09-29 04:39:14
合計ジャッジ時間 67,529 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,272 KB
testcase_01 AC 72 ms
71,328 KB
testcase_02 AC 73 ms
71,268 KB
testcase_03 AC 70 ms
71,276 KB
testcase_04 AC 85 ms
76,720 KB
testcase_05 AC 80 ms
76,712 KB
testcase_06 AC 82 ms
76,764 KB
testcase_07 AC 83 ms
76,544 KB
testcase_08 AC 83 ms
76,616 KB
testcase_09 AC 81 ms
76,688 KB
testcase_10 MLE -
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
evil_0.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
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)-96 for s in S]
mod = 10**9+7
r = 1234

H = [[0]*N for _ in range(N)]  # H[i][j] = S[i:j+1]のRolling Hash
for i in range(N):
    h = 0
    for j in range(i,N):
        h *= r
        h += ord_S[j]
        h %= mod
        H[i][j] = h

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 H[i][j] == H[N-1-j][N-1-i]:
            x += dp[j+1]
            x %= mod
    dp[i] = x

ans = dp[0]
print(ans)
0