結果
| 問題 |
No.2099 [Cherry Alpha B] Time Machine
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:30:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,061 bytes |
| コンパイル時間 | 348 ms |
| コンパイル使用メモリ | 82,392 KB |
| 実行使用メモリ | 60,196 KB |
| 最終ジャッジ日時 | 2025-06-12 16:30:39 |
| 合計ジャッジ時間 | 6,040 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 63 WA * 9 |
ソースコード
def minimal_time():
import sys
T = int(sys.stdin.readline())
X, A = map(int, sys.stdin.readline().split())
Y, B = map(int, sys.stdin.readline().split())
min_cost = float('inf')
# We'll try a up to a certain maximum, say 1e6, to find a good solution
max_a = 10**6 if A != 0 else 0 # Avoid division by zero
# Check for T >=0
if T >= 0:
# Try a from 0 to max_a
for a in range(0, max_a + 1):
numerator = a * A - T
if numerator <= 0:
b = 0
else:
b = (numerator + B - 1) // B # ceil division
c = T - a * A + b * B
if c < 0:
continue
cost = a * X + b * Y + c
if cost < min_cost:
min_cost = cost
else:
# T is negative, b must be at least ceil( (-T)/B )
required = -T
b_min = (required + B - 1) // B # ceil division
# Now, try a from 0 to max_a
for a in range(0, max_a + 1):
numerator = a * A - T
if numerator <= 0:
b = b_min
else:
b = max(b_min, (numerator + B - 1) // B)
c = T - a * A + b * B
if c < 0:
continue
cost = a * X + b * Y + c
if cost < min_cost:
min_cost = cost
# Also, try cases where a is as large as possible
# For T >=0, a_max = T // A
if T >= 0 and A != 0:
a_max = T // A
for a in [a_max - 1, a_max, a_max + 1]:
if a < 0:
continue
numerator = a * A - T
if numerator <= 0:
b = 0
else:
b = (numerator + B - 1) // B
c = T - a * A + b * B
if c < 0:
continue
cost = a * X + b * Y + c
if cost < min_cost:
min_cost = cost
print(min_cost)
minimal_time()
gew1fw