結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー bit_kyoprobit_kyopro
提出日時 2022-10-14 22:05:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 59,648 KB
最終ジャッジ日時 2024-06-26 14:36:28
合計ジャッジ時間 10,253 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())
x, a = map(int, input().split())
y, b = map(int, input().split())

x = min(x, a)

ans = 10**20

if t >= 0:
    for c2 in range(10**7 + 1):
        now = c2*a
        cost = c2*x
        if now <= t:
            cost += t - now
        else:
            c3 = (now - t + b - 1)//b
            now -= c3*b
            cost += c3*y + t - now
        ans = min(ans, cost)
else:
    c3 = (-t + b - 1)//b
    for _ in range(10**7 + 1):
        cost = c3*y
        now = -c3*b
        c2 = (t - now)//a
        cost += c2*x
        now += c2*a
        cost += t - now
        ans = min(ans, cost)
        c3 += 1
print(ans)
0