結果
| 問題 |
No.599 回文かい
|
| コンテスト | |
| ユーザー |
htkb
|
| 提出日時 | 2019-02-08 21:13:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 180 ms / 4,000 ms |
| コード長 | 715 bytes |
| コンパイル時間 | 131 ms |
| コンパイル使用メモリ | 82,036 KB |
| 実行使用メモリ | 80,000 KB |
| 最終ジャッジ日時 | 2024-06-28 18:01:54 |
| 合計ジャッジ時間 | 2,307 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
S = [ord(c)-97 for c in input()]
#S = [ord("a")]*(10**4)
length = len(S)
mod = 10**9+7
left_kc, right_kc = S[:length//2], S[::-1][:length//2]
S = None
p = 1
for i in range(length//2):
left_kc[i] = (left_kc[i] * p) % mod
p = p * 10 % mod
dp = [0]*(length//2+1)
def rec(left):
count = 1
left_hash, right_hash = 0, 0
m = pow(10, left, mod)
for i in range(left, length//2):
left_hash = (left_hash + left_kc[i]) % mod
right_hash = (right_hash * 10 + right_kc[i]*m) % mod
if left_hash == right_hash:
count += dp[i+1] or rec(i+1)
count %= mod
dp[left] = count % mod
return dp[left]
print(rec(0))
htkb