結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 12:53:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,799 bytes |
| コンパイル時間 | 385 ms |
| コンパイル使用メモリ | 82,336 KB |
| 実行使用メモリ | 306,704 KB |
| 最終ジャッジ日時 | 2025-06-12 12:56:52 |
| 合計ジャッジ時間 | 6,038 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 MLE * 6 -- * 3 |
ソースコード
s = input().strip()
count = 0
while True:
applied_1 = 0
# Apply operation 1 as many times as possible
s_list = list(s)
new_s = []
i = 0
n = len(s_list)
while i <= n - 5:
if (s_list[i] == 'p' and s_list[i+1] == 'h' and s_list[i+2] == 'n' and s_list[i+3] == 'o' and s_list[i+4] == 'm'):
new_s.extend(['p', 'e', 'n', 'h'])
applied_1 += 1
i += 5
else:
new_s.append(s_list[i])
i += 1
# Add remaining characters
while i < n:
new_s.append(s_list[i])
i += 1
new_s_str = ''.join(new_s)
if applied_1 > 0:
count += applied_1
s = new_s_str
# Now apply operation 2 once
# Remove all 'h's and replace 'e's with 'h's
temp_list = []
e_count = 0
for c in s:
if c != 'h':
temp_list.append(c)
if c == 'e':
e_count += 1
# Replace 'e's with 'h's
temp_list = ['h' if c == 'e' else c for c in temp_list]
new_s_after_op2 = ''.join(temp_list)
if new_s_after_op2 != s:
count += 1
s = new_s_after_op2
else:
break # No change, can't apply operation 2
else:
# Try to apply operation 2 once
temp_list = []
e_count = 0
for c in s:
if c != 'h':
temp_list.append(c)
if c == 'e':
e_count += 1
# Replace 'e's with 'h's
temp_list = ['h' if c == 'e' else c for c in temp_list]
new_s_after_op2 = ''.join(temp_list)
if new_s_after_op2 != s:
count += 1
s = new_s_after_op2
else:
break # No more operations possible
print(count)
gew1fw