結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー ikoma
提出日時 2022-10-14 21:53:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 626 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 61,400 KB
最終ジャッジ日時 2024-06-26 13:47:37
合計ジャッジ時間 5,154 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 59 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

T=int(input())
X,A=map(int,input().split())
Y,B=map(int,input().split())

def solve(na:int):
    x = A*na
    t=X*na
    if x <= T:
        return (T-x) + t
    d = x-T
    nb = (d+B-1)//B
    t += Y*nb
    x -= B*nb
    return t + (T-x)

low = 0
high = 10**7
ans = 10**9

while low+10000<high:
    c1 = (low*2+high)//3
    c2 = (low+high*2)//3

    t1 = solve(c1)
    t2 = solve(c2)

    if t1<t2:
        if high==c2:break
        high = c2
        ans = min(ans, t1)
    else:
        if low==c1:break
        ans = min(ans, t2)
        low = c1
for i in range(low,high+1):
    t = solve(i)
    ans = min(ans, t)
print(ans)
0