結果
| 問題 | 
                            No.996 Phnom Penh
                             | 
                    
| コンテスト | |
| ユーザー | 
                             convexineq
                         | 
                    
| 提出日時 | 2020-02-21 23:28:48 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,570 bytes | 
| コンパイル時間 | 267 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 12,588 KB | 
| 最終ジャッジ日時 | 2024-10-09 02:34:57 | 
| 合計ジャッジ時間 | 2,285 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 WA * 1 | 
| other | AC * 11 WA * 14 | 
ソースコード
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
#n,*a = [int(i) for i in read().split()]
#a = [int(i) for i in readline().split()]
#n = int(input())
s = input()
ans = 0
c = s.count("phnom")
if c==0: 
    if "h" in s or "e" in s:
        ans = 1
        s = s.replace("h","").replace("e","h")
        c = s.count("phnom")
        if c==0:
            if "h" in s or "e" in s:
                print(ans+1)
                exit()
            else:
                print(ans)
                exit()
    else:
        print(0)
        exit()
s = s.replace("phnom","penh").replace("h","").replace("e","h")
ans += c+1
c = s.count("phnom")
if c==0: 
    if "h" in s or "e" in s:
        ans = 1
        s = s.replace("h","").replace("e","h")
        c = s.count("phnom")
        if c==0:
            if "h" in s or "e" in s:
                print(ans+1)
                exit()
            else:
                print(ans)
                exit()
    else:
        print(0)
        exit()
s = s.replace("phn","X").replace("om","Y")
def getans(s,ans):
    q = []
    res = 0
    depth = 0
    for i in s[::-1]:
        if not q: q.append(i)
        else:
            if i=="X":
                r = 0
                while q and q[-1]=="Y":
                    q.pop()
                    r += 1
                res += r
                depth = max(depth,r)
            q.append(i)
    
    
    if res==0:
        print(ans+1)
        exit()
    else:
        print(ans+res+depth+1)
getans(s,ans)
    
            
            
            
        
            
convexineq