結果
| 問題 |
No.740 幻の木
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-26 15:47:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,386 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 82,516 KB |
| 実行使用メモリ | 59,820 KB |
| 最終ジャッジ日時 | 2025-03-26 15:48:43 |
| 合計ジャッジ時間 | 1,170 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
N, M, P, Q = map(int, input().split())
current_month = 1
current_leaves = N
answer = 0
end_month_storm = P + Q - 1
while current_leaves > 0:
if P <= current_month <= end_month_storm:
# Windy season
remaining_storm = end_month_storm - current_month + 1
storm_reduce = remaining_storm * 2 * M
if current_leaves <= storm_reduce:
needed = (current_leaves + 2 * M - 1) // (2 * M)
answer += needed
break
else:
current_leaves -= storm_reduce
answer += remaining_storm
current_month = end_month_storm + 1
current_month = current_month % 12
if current_month == 0:
current_month = 12
else:
# Regular season
if current_month < P:
months_until_storm = P - current_month
else:
months_until_storm = (12 - current_month) + P
normal_reduce = months_until_storm * M
if current_leaves <= normal_reduce:
needed = (current_leaves + M - 1) // M
answer += needed
break
else:
current_leaves -= normal_reduce
answer += months_until_storm
current_month += months_until_storm
current_month = current_month % 12
if current_month == 0:
current_month = 12
print(answer)
lam6er