結果

問題 No.464 PPAP
ユーザー H3PO4H3PO4
提出日時 2020-09-07 13:29:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,864 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 274,140 KB
最終ジャッジ日時 2023-08-19 16:38:19
合計ジャッジ時間 13,835 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,472 KB
testcase_01 AC 74 ms
71,084 KB
testcase_02 AC 73 ms
71,168 KB
testcase_03 AC 73 ms
71,164 KB
testcase_04 AC 88 ms
76,368 KB
testcase_05 AC 84 ms
76,140 KB
testcase_06 AC 80 ms
76,076 KB
testcase_07 AC 137 ms
85,284 KB
testcase_08 AC 136 ms
85,000 KB
testcase_09 AC 119 ms
85,212 KB
testcase_10 AC 1,864 ms
273,416 KB
testcase_11 AC 929 ms
203,080 KB
testcase_12 AC 1,628 ms
273,180 KB
testcase_13 AC 1,125 ms
274,140 KB
testcase_14 AC 1,816 ms
273,412 KB
testcase_15 AC 75 ms
71,160 KB
testcase_16 AC 74 ms
71,276 KB
testcase_17 AC 74 ms
71,220 KB
testcase_18 AC 75 ms
71,172 KB
testcase_19 AC 79 ms
76,148 KB
testcase_20 AC 81 ms
76,084 KB
testcase_21 AC 79 ms
76,168 KB
testcase_22 AC 78 ms
76,072 KB
testcase_23 AC 1,109 ms
273,844 KB
testcase_24 AC 1,146 ms
273,772 KB
testcase_25 AC 1,126 ms
273,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def substring_palindrome(S):
    L = len(S)
    table = [[False] * L for _ in range(L)]
    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 = ([0] * L for _ in range(4))
table = substring_palindrome(S)

for i in range(L):
    # PPAP
    for j in range(i + 1):
        if table[j][i]:
            PPAP[i] += PPA[j - 1]

    # PPA
    PPA[i] += sum(PP[:i])

    # PP
    for j in range(i + 1):
        if table[j][i]:
            PP[i] += P[j - 1]

    # P
    if table[0][i]:
        P[i] += 1

print(PPAP[-1])
0