結果

問題 No.599 回文かい
ユーザー torikuminotorikumino
提出日時 2019-05-04 16:05:00
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 258 ms / 4,000 ms
コード長 351 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 76,592 KB
最終ジャッジ日時 2023-09-05 04:31:49
合計ジャッジ時間 4,337 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,312 KB
testcase_01 AC 76 ms
71,092 KB
testcase_02 AC 79 ms
71,264 KB
testcase_03 AC 76 ms
71,292 KB
testcase_04 AC 88 ms
75,844 KB
testcase_05 AC 87 ms
76,088 KB
testcase_06 AC 90 ms
75,904 KB
testcase_07 AC 91 ms
76,100 KB
testcase_08 AC 91 ms
76,064 KB
testcase_09 AC 87 ms
76,036 KB
testcase_10 AC 168 ms
76,592 KB
testcase_11 AC 129 ms
76,520 KB
testcase_12 AC 162 ms
76,192 KB
testcase_13 AC 133 ms
76,352 KB
testcase_14 AC 194 ms
76,528 KB
testcase_15 AC 214 ms
76,400 KB
testcase_16 AC 239 ms
76,508 KB
testcase_17 AC 258 ms
76,384 KB
testcase_18 AC 82 ms
75,360 KB
testcase_19 AC 84 ms
74,900 KB
testcase_20 AC 84 ms
75,228 KB
evil_0.txt AC 177 ms
76,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
p = 65537
m = 10**9+7
h, w = [0], [1]
for c in s:
    h.append((h[-1]*p+ord(c))%m)
    w.append(w[-1]*p%m)
def H(i, j):
    return (h[j]-h[i]*w[j-i])%m
n = len(s)//2+1
dp = [1]*n
for i in range(n)[::-1]:
    for j in range(i+1, n):
        if H(i, j) == H(len(s)-j, len(s)-i):
            dp[i] += dp[j]
            dp[i] %= m
print(dp[0])
0