結果

問題 No.996 Phnom Penh
ユーザー titia
提出日時 2020-02-21 23:22:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,489 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-10-09 02:27:45
合計ジャッジ時間 3,734 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

S=input()
LEN=len(S)
S+="z"*100

D1=[]
D2=[]

for i in range(LEN):
    if S[i:i+3]=="phn":
        ind=i+3
        count=0
        while True:
            if S[ind]=="h" or S[ind]=="e":
                ind+=1
            elif count%2==0 and S[ind]=="o":
                ind+=1
                count+=1
            elif count%2==1 and S[ind]=="m":
                ind+=1
                count+=1
            else:
                break

        #print(i,ind)

        D1.append(count//2)

for i in range(LEN):
    if S[i:i+2]=="om":
        ind=i-1
        while ind>=0 and S[ind]=="h":
            ind-=1

        #print(i,ind)

        if S[ind-2:ind+1]=="pen":

            ind2=i

            count=0
            while True:
                if S[ind2]=="h" or S[ind2]=="e":
                    ind2+=1
                elif count%2==0 and S[ind2]=="o":
                    ind2+=1
                    count+=1
                elif count%2==1 and S[ind2]=="m":
                    ind2+=1
                    count+=1
                else:
                    break

            D2.append(count//2)


if D1==[] and D2==[]:
    if "e" in S:
        print(2)
    elif "h" in S:
        print(1)
    else:
        print(0)
else:
    if D2==[]:
        print(sum(D1)+max(D1)+1)
    elif D1==[]:
        print(sum(D2)+max(D2)+2)
    else:
        if max(D1)>max(D2):
            print(sum(D1)+sum(D2)+max(D1)+1)
        else:
            print(sum(D1)+sum(D2)+max(D2)+2)
            
        
0