結果

問題 No.465 PPPPPPPPPPPPPPPPAPPPPPPPP
ユーザー りあんりあん
提出日時 2020-11-23 06:28:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,993 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 289,012 KB
最終ジャッジ日時 2023-09-30 23:37:38
合計ジャッジ時間 14,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,316 KB
testcase_01 AC 72 ms
71,408 KB
testcase_02 AC 73 ms
71,220 KB
testcase_03 AC 72 ms
71,264 KB
testcase_04 AC 71 ms
71,364 KB
testcase_05 AC 173 ms
103,872 KB
testcase_06 AC 426 ms
217,432 KB
testcase_07 AC 225 ms
109,144 KB
testcase_08 AC 535 ms
232,120 KB
testcase_09 AC 645 ms
223,732 KB
testcase_10 AC 611 ms
223,040 KB
testcase_11 AC 1,993 ms
289,012 KB
testcase_12 AC 1,420 ms
271,180 KB
testcase_13 AC 831 ms
235,620 KB
testcase_14 AC 1,257 ms
271,108 KB
testcase_15 AC 527 ms
216,372 KB
testcase_16 AC 497 ms
212,336 KB
testcase_17 AC 493 ms
213,088 KB
testcase_18 AC 617 ms
244,316 KB
testcase_19 AC 489 ms
211,460 KB
testcase_20 AC 504 ms
203,972 KB
testcase_21 AC 817 ms
263,260 KB
32_ratsliveonnoevilstar.txt AC 510 ms
201,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools


def pal(s_):
    s = "^" + s_
    n = len(s)
    pl = [[0, 0, 0] for _ in range(n)]
    pl[0][0] = 1
    gpl = [[0, 0, 0] for _ in range(n)]
    g = []
    for j in range(1, n):
        g1 = [(i - 1, d, k) for i, d, k in g if i > 0 and s[i - 1] == s[j]]
        g2 = []
        r = -j
        for i, d, k in g1:
            if i - r != d:
                g2.append((i, i - r, 1))
                if k > 1:
                    g2.append((i + d, d, k - 1))
            else:
                g2.append((i, d, k))
            r = i + (k - 1) * d
        if j > 1 and s[j - 1] == s[j]:
            g2.append((j - 1, j - 1 - r, 1))
            r = j - 1
        g2.append((j, j - r, 1))
        g = []
        for i, d, k in g2:
            if not g or g[-1][1] != d:
                g.append((i, d, k))
            else:
                g[-1] = (g[-1][0], g[-1][1], g[-1][2] + k)
        # pl[j] = 0
        for i, d, k in g:
            r = i + (k - 1) * d
            m = [0, pl[r - 1][0], pl[r - 1][1]]
            if k > 1:
                for l in range(3):
                    m[l] += gpl[i - d][l]
            if d <= i:
                gpl[i - d] = m
            for l in range(3):
                pl[j][l] += m[l]
    return (pl, g)


pl, g = pal(input())
accum = list(itertools.accumulate([i[-1] for i in pl]))
ans = 0
for i, d, k in g:
    for j in range(k):
        if i + d * j > 1:
            ans += accum[i + d * j - 2]

print(ans)
0