結果

問題 No.464 PPAP
ユーザー maspymaspy
提出日時 2023-05-28 04:31:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 484 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 54,652 KB
最終ジャッジ日時 2023-08-27 03:39:21
合計ジャッジ時間 8,269 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
29,752 KB
testcase_01 AC 139 ms
29,772 KB
testcase_02 AC 140 ms
29,848 KB
testcase_03 AC 136 ms
29,852 KB
testcase_04 AC 139 ms
29,736 KB
testcase_05 AC 139 ms
29,860 KB
testcase_06 AC 139 ms
29,744 KB
testcase_07 AC 154 ms
30,624 KB
testcase_08 AC 155 ms
30,836 KB
testcase_09 AC 156 ms
30,936 KB
testcase_10 AC 479 ms
54,528 KB
testcase_11 AC 352 ms
45,680 KB
testcase_12 AC 482 ms
54,416 KB
testcase_13 AC 478 ms
54,316 KB
testcase_14 AC 477 ms
54,588 KB
testcase_15 AC 137 ms
29,704 KB
testcase_16 AC 137 ms
29,828 KB
testcase_17 AC 137 ms
29,788 KB
testcase_18 AC 137 ms
29,780 KB
testcase_19 AC 140 ms
29,824 KB
testcase_20 AC 140 ms
29,900 KB
testcase_21 AC 140 ms
29,704 KB
testcase_22 AC 138 ms
29,824 KB
testcase_23 AC 479 ms
54,480 KB
testcase_24 AC 474 ms
54,356 KB
testcase_25 AC 484 ms
54,652 KB
権限があれば一括ダウンロードができます

ソースコード

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