結果

問題 No.464 PPAP
ユーザー mkawa2mkawa2
提出日時 2020-04-30 11:50:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,778 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 80,804 KB
最終ジャッジ日時 2023-08-21 15:01:53
合計ジャッジ時間 6,033 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
75,352 KB
testcase_01 AC 71 ms
71,224 KB
testcase_02 AC 71 ms
70,944 KB
testcase_03 AC 70 ms
70,972 KB
testcase_04 AC 82 ms
75,912 KB
testcase_05 AC 79 ms
75,960 KB
testcase_06 AC 72 ms
71,264 KB
testcase_07 AC 500 ms
76,444 KB
testcase_08 AC 118 ms
76,296 KB
testcase_09 AC 79 ms
75,328 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 #

import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

# 偶数長、奇数長含めて回文「直径」(つまり全長)を返す
# s[i]の前の隙間を中心とした回文長がres[i*2](偶数長)
# s[i]を中心とした回文長がres[i*2+1](奇数長)
# si  0 1 2 3 4 5
# s   a b a a b a
# d  0103016103010
# di 0123456789...
# dummyがsに入っていないか注意
def Manacher(s):
    dummy="@"
    s = dummy + dummy.join(s) + dummy
    i=j=0
    res=[-1]*len(s)
    while i<len(s):
        while i-j>=0 and i+j<len(s) and s[i-j]==s[i+j]:j+=1
        res[i]=j-1
        k=1
        while i-k>=0 and k+res[i-k]+1<j:
            res[i+k]=res[i-k]
            k+=1
        i+=k
        j-=k
    return res

def main():
    s=SI()
    dd=Manacher(s)
    ans=0
    for i in range(1,len(s)-2):
        # i==dd[i]だと先頭から回文ができている
        if i==dd[i]:
            # 2つ目の回文長の限界
            lim2=len(s)-i-2
            for j in range(i*2+1,lim2+i*2+1):
                if j-i*2<=dd[j]:
                    # 2つの回文長の合計
                    n12=j-i
                    # 3つ目の回文長の限界
                    lim3=len(s)-n12-1
                    #print(i,j,dd[i],dd[j],lim3)
                    for k in range(len(dd)-2,len(s)*2-lim3-1,-1):
                        if k+dd[k]==len(s)*2:
                            #print(i,j,k,dd[i],dd[j],dd[k])
                            ans+=1
    print(ans)

main()
0