結果

問題 No.996 Phnom Penh
ユーザー lam6er
提出日時 2025-04-16 15:25:53
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,048 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 81,644 KB
実行使用メモリ 299,660 KB
最終ジャッジ日時 2025-04-16 15:27:47
合計ジャッジ時間 5,264 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 MLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

def apply_op1(s):
    new_s = []
    i = 0
    count = 0
    n = len(s)
    while i <= n - 5:
        if s[i:i+5] == 'phnom':
            new_s.append('penh')
            count += 1
            i += 5
        else:
            new_s.append(s[i])
            i += 1
    # Add the remaining characters
    new_s.append(s[i:])
    return ''.join(new_s), count

def apply_op2(s):
    # Remove all 'h's
    s_no_h = s.replace('h', '')
    # Replace all 'e's with 'h's
    s_new = s_no_h.replace('e', 'h')
    return s_new

s = input().strip()
count = 0

while True:
    # Apply operation 1 as many times as possible
    op1_applied = False
    new_s, op1_count = apply_op1(s)
    if op1_count > 0:
        count += op1_count
        s = new_s
        op1_applied = True

    if op1_applied:
        continue  # Try operation 1 again if applied

    # Apply operation 2 once if possible
    new_s_op2 = apply_op2(s)
    if new_s_op2 != s:
        count += 1
        s = new_s_op2
    else:
        break  # No more operations can be applied

print(count)
0