結果

問題 No.464 PPAP
ユーザー H3PO4H3PO4
提出日時 2020-09-07 13:21:33
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 947 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 665,348 KB
最終ジャッジ日時 2023-08-19 16:36:58
合計ジャッジ時間 6,156 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 70 ms
71,604 KB
testcase_02 AC 73 ms
71,132 KB
testcase_03 AC 70 ms
71,236 KB
testcase_04 AC 88 ms
76,748 KB
testcase_05 AC 86 ms
76,880 KB
testcase_06 AC 78 ms
76,232 KB
testcase_07 AC 386 ms
139,036 KB
testcase_08 AC 304 ms
120,940 KB
testcase_09 AC 123 ms
77,148 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 #

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


S = input()

L = len(S)
P, PP, PPA, PPAP = ([0] * L for _ in range(4))
palindrome = set(substring_palindrome(S))

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

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

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

    # P
    if (0, i) in palindrome:
        P[i] += 1

print(PPAP[-1])
0