結果
| 問題 |
No.996 Phnom Penh
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:35:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,793 bytes |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 82,632 KB |
| 実行使用メモリ | 111,544 KB |
| 最終ジャッジ日時 | 2025-03-20 20:36:37 |
| 合計ジャッジ時間 | 5,686 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 TLE * 1 -- * 3 |
ソースコード
S = input().strip()
ans = 0
while True:
# Apply operation1 as much as possible
operation1_done = False
while True:
# Count and replace all occurrences of 'phnom'
new_S = []
i = 0
count_op1 = 0
len_S = len(S)
while i <= len_S - 5:
if S[i:i+5] == 'phnom':
new_S.append('penh')
count_op1 += 1
i += 5
else:
new_S.append(S[i])
i += 1
# Add remaining characters
new_S.extend(S[i:])
new_S_str = ''.join(new_S)
if count_op1 == 0:
break
ans += count_op1
S = new_S_str
operation1_done = True
if operation1_done:
# Check if new S contains 'phnom' again after replacing
if 'phnom' in S:
continue # Restart the loop to process operation1 again
else:
operation1_done = False
# Apply operation2 as many times as possible
applied_op2 = False
while True:
s1 = S.replace('h', '').replace('e', 'h')
if s1 == S:
break # No change, can't apply
# Apply once
ans += 1
applied_op2 = True
prev_S = S
S = s1
# Check after first application
if 'phnom' in S:
break # Need to restart loop for operation1
# Apply second time if possible
s2 = S.replace('h', '').replace('e', 'h')
if s2 == S:
break # No further change
ans += 1
S = s2
# Check after second application
if 'phnom' in S:
break
if applied_op2 and 'phnom' in S:
continue # Restart loop for operation1
else:
break # No more possible operations
print(ans)
lam6er