結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー titia
提出日時 2025-01-11 00:35:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,087 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 3,077 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 108,092 KB
最終ジャッジ日時 2025-01-11 00:35:16
合計ジャッジ時間 6,484 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

t=int(input())
for tests in range(t):
    S=input().strip()

    ANS=[1<<60]*len(S)
    ANS2=[1<<60]*len(S)
    PLUS=[0]*len(S)

    for i in range(len(S)):
        s=S[i:i+4]

        if len(s)==4:
            score=0
            if s[0]!="g":
                score+=1
            if s[1]!="o":
                score+=1
            if s[2]!="o":
                score+=1
            if s[3]!="d":
                score+=1

            ANS[i]=score

        s=S[i:i+7]

        if len(s)==7:
            score=0
            if s[0]!="p":
                score+=1
            if s[1]!="r":
                score+=1
            if s[2]!="o":
                score+=1
            if s[3]!="b":
                score+=1
            if s[4]!="l":
                score+=1
            if s[5]!="e":
                score+=1
            if s[6]!="m":
                score+=1

            ANS2[i]=score
            if score==0:
                PLUS[i+1]=1

    #print(ANS)
    #print(ANS2)
    #print(PLUS)
            
    for i in range(1,len(S)):
        PLUS[i]+=PLUS[i-1]

    for i in range(len(S)-2,-1,-1):
        ANS2[i]=min(ANS2[i+1],ANS2[i])

    LANS=1<<64

    for i in range(len(S)-4):
        LANS=min(LANS,ANS[i]+ANS2[i+4]+PLUS[i])
        if ANS[i]==0:
            break

    print(LANS)
0