結果

問題 No.996 Phnom Penh
ユーザー gew1fw
提出日時 2025-06-12 12:51:39
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,162 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,908 KB
実行使用メモリ 303,240 KB
最終ジャッジ日時 2025-06-12 12:51:45
合計ジャッジ時間 6,126 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 MLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

def max_operations(s):
    count = 0
    prev = None
    while True:
        # Apply operation 1 as many times as possible
        cnt1 = 0
        new_s = []
        i = 0
        n = len(s)
        while i <= n - 5:
            if s[i:i+5] == 'phnom':
                new_s.append('penh')
                cnt1 += 1
                i += 5
            else:
                new_s.append(s[i])
                i += 1
        # Add remaining characters
        while i < n:
            new_s.append(s[i])
            i += 1
        if cnt1 > 0:
            count += cnt1
            s = ''.join(new_s)
            prev = None
            continue  # go back to check operation 1 again
        
        # Apply operation 2 once if possible
        # Check if applying operation 2 changes the string
        # Step 1: remove all 'h's
        temp = s.replace('h', '')
        # Step 2: replace all 'e's with 'h's
        temp2 = temp.replace('e', 'h')
        if temp2 != s:
            count += 1
            s = temp2
            prev = s
        else:
            break  # no more operations possible
    return count

s = input().strip()
print(max_operations(s))
0