結果

問題 No.464 PPAP
ユーザー maspy
提出日時 2023-05-28 04:31:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 834 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 68,260 KB
最終ジャッジ日時 2024-12-26 10:56:54
合計ジャッジ時間 17,335 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

S = np.array(list(read().rstrip()), np.int8)
N = len(S)

is_palind = np.zeros((N + 1, N + 1), np.bool_)
is_palind[0] = 1
is_palind[1, :-1] = 1
for n in range(2, N + 1):
    is_palind[n, : N + 1 - n] = is_palind[n - 2, 1: N + 2 - n]
    is_palind[n, : N + 1 - n] &= (S[:N + 1 - n] == S[n - 1:N])

P = np.zeros(N, np.int64)
P += is_palind[1:, 0] * 1

PP = np.zeros_like(P)
for i, x in enumerate(P):
    PP[i + 1:] += x * is_palind[1: N - i, i + 1]

PPA = np.zeros_like(PP)
PPA[1:] = np.cumsum(PP[:-1])

PPAP = np.zeros_like(P)
for i, x in enumerate(PPA):
    PPAP[i + 1:] += x * is_palind[1: N - i, i + 1]

print(PPAP[-1])
0