結果

問題 No.464 PPAP
ユーザー しらっ亭しらっ亭
提出日時 2016-11-25 18:23:30
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,104 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-05-05 15:53:40
合計ジャッジ時間 5,758 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,144 KB
testcase_01 AC 10 ms
6,144 KB
testcase_02 AC 9 ms
6,144 KB
testcase_03 AC 10 ms
6,144 KB
testcase_04 AC 10 ms
6,272 KB
testcase_05 AC 11 ms
6,144 KB
testcase_06 AC 10 ms
6,144 KB
testcase_07 AC 113 ms
6,400 KB
testcase_08 AC 27 ms
6,400 KB
testcase_09 AC 12 ms
6,400 KB
testcase_10 TLE -
testcase_11 AC 604 ms
6,528 KB
testcase_12 AC 965 ms
6,784 KB
testcase_13 AC 21 ms
6,400 KB
testcase_14 AC 52 ms
6,656 KB
testcase_15 AC 10 ms
6,272 KB
testcase_16 AC 10 ms
6,144 KB
testcase_17 AC 10 ms
6,272 KB
testcase_18 AC 10 ms
6,144 KB
testcase_19 AC 10 ms
6,272 KB
testcase_20 AC 9 ms
6,016 KB
testcase_21 AC 10 ms
6,016 KB
testcase_22 AC 10 ms
6,016 KB
testcase_23 AC 23 ms
6,400 KB
testcase_24 AC 22 ms
6,528 KB
testcase_25 AC 21 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def manachar(s):
    def get(i):
        return '^' if i & 1 else s[i>>1]

    size = len(s) * 2 - 1
    rads = [0] * size

    i = j = 0
    while i < size:
        while i - j >= 0 and i + j < size and get(i - j) == get(i + j):
            j += 1
        rads[i] = j
        k = 1

        while i - k >= 0 and i + k < size and k + rads[i - k] < j:
            rads[i + k] = rads[i - k]
            k += 1

        i += k
        j -= k

    return rads


def solve():
    s = raw_input()
    n = len(s)

    rads = manachar(s)

    def is_palindrome(l, r):
        return rads[l + r] >= r - l + 1

    p1 = []

    for i in xrange(n - 3):
        if is_palindrome(0, i):
            p1.append(i)

    p2 = [0] * n

    for i in p1:
        for j in xrange(i + 1, n - 2):
            if is_palindrome(i + 1, j):
                p2[j] += 1

    sum_p2 = [0] * n
    for i in xrange(n - 1):
        sum_p2[i + 1] = sum_p2[i] + p2[i]

    ans = 0

    for k in xrange(2, n - 1):
        if is_palindrome(k + 1, n - 1):
            ans += sum_p2[k]

    print(ans)


if __name__ == '__main__':
    solve()
0