結果

問題 No.464 PPAP
ユーザー H3PO4H3PO4
提出日時 2022-01-28 10:03:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 945 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 47,368 KB
最終ジャッジ日時 2023-08-27 20:24:00
合計ジャッジ時間 5,925 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
36,664 KB
testcase_01 AC 144 ms
29,608 KB
testcase_02 AC 144 ms
29,544 KB
testcase_03 AC 146 ms
29,612 KB
testcase_04 AC 144 ms
29,704 KB
testcase_05 AC 144 ms
29,724 KB
testcase_06 AC 143 ms
29,580 KB
testcase_07 AC 395 ms
31,212 KB
testcase_08 AC 330 ms
31,188 KB
testcase_09 AC 168 ms
31,376 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def substring_palindrome(S):
    L = len(S)
    table = np.zeros((L, L), dtype=bool)
    for i in range(L):
        # 奇数長
        j = 0
        while 0 <= i - j and i + j < L:
            if S[i - j] == S[i + j]:
                table[i - j][i + j] = True
                j += 1
            else:
                break
        # 偶数長
        j = 0
        while 0 <= i - j and i + j + 1 < L:
            if S[i - j] == S[i + j + 1]:
                table[i - j][i + j + 1] = True
                j += 1
            else:
                break

    return table


S = input()

L = len(S)
P, PP, PPA, PPAP = (np.zeros(L, dtype=np.int64) for _ in range(4))
table = np.array(substring_palindrome(S))

for i in range(L):
    # PPAP
    PPAP[i] = np.sum(PPA[:-1] * table[1:, i])

    # PPA
    PPA[i] = np.sum(PP[:i])

    # PP
    PP[i] = np.sum(P[:-1] * table[1:, i])

    # P
    P[i] = table[0, i]

print(PPAP[-1])
0