結果

問題 No.996 Phnom Penh
ユーザー yomo3
提出日時 2020-02-22 03:34:06
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 15,656 KB
最終ジャッジ日時 2024-10-09 13:51:42
合計ジャッジ時間 1,950 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

import re

s = input()

ans = 0
c_op12 = 0
tr = str.maketrans('e', 'h', 'h')
while True:
    n = s.count('phnom')
    if n > 0:
        s = s.replace('phnom', 'penh').translate(tr)
        ans += n + 1
        c_op12 += 1
        if c_op12 == 2:
            match = re.findall('(phn(om)+)', s)
            if match:
                c = [(len(m[0])- 3) // 2 for m in match]
                ans += sum(c) + max(c)
            ans += 1 # 最後の操作2の分
            break
    elif 'h' in s or 'e' in s:
        s = s.translate(tr)
        ans += 1
    else:
        break
print(ans)
0