結果

問題 No.464 PPAP
ユーザー H3PO4H3PO4
提出日時 2020-09-07 13:26:49
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 977 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 274,628 KB
最終ジャッジ日時 2023-08-19 16:38:01
合計ジャッジ時間 16,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,932 KB
testcase_01 AC 73 ms
71,280 KB
testcase_02 AC 71 ms
71,112 KB
testcase_03 AC 71 ms
71,408 KB
testcase_04 AC 91 ms
76,368 KB
testcase_05 AC 90 ms
76,304 KB
testcase_06 AC 79 ms
75,988 KB
testcase_07 AC 162 ms
85,604 KB
testcase_08 AC 155 ms
85,716 KB
testcase_09 AC 119 ms
85,068 KB
testcase_10 TLE -
testcase_11 AC 1,012 ms
203,316 KB
testcase_12 AC 1,758 ms
273,492 KB
testcase_13 AC 1,175 ms
274,628 KB
testcase_14 TLE -
testcase_15 AC 75 ms
71,012 KB
testcase_16 AC 75 ms
71,264 KB
testcase_17 AC 76 ms
71,336 KB
testcase_18 AC 76 ms
71,372 KB
testcase_19 AC 82 ms
76,048 KB
testcase_20 AC 82 ms
76,052 KB
testcase_21 AC 81 ms
75,860 KB
testcase_22 AC 82 ms
75,960 KB
testcase_23 AC 1,164 ms
274,364 KB
testcase_24 AC 1,115 ms
273,744 KB
testcase_25 AC 1,168 ms
274,024 KB
権限があれば一括ダウンロードができます

ソースコード

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))
table = [[False] * L for _ in range(L)]
for p,q in substring_palindrome(S):
    table[p][q] = True

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