結果

問題 No.464 PPAP
ユーザー mkawa2mkawa2
提出日時 2020-04-30 11:49:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,809 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 12,556 KB
最終ジャッジ日時 2023-08-21 15:01:07
合計ジャッジ時間 4,347 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,528 KB
testcase_01 AC 16 ms
7,984 KB
testcase_02 AC 16 ms
8,072 KB
testcase_03 AC 16 ms
8,108 KB
testcase_04 AC 33 ms
8,048 KB
testcase_05 AC 18 ms
8,056 KB
testcase_06 AC 16 ms
8,192 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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

sys.setrecursionlimit(10 ** 6)
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