結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー gew1fw
提出日時 2025-06-12 19:04:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,152 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,968 KB
実行使用メモリ 75,488 KB
最終ジャッジ日時 2025-06-12 19:04:36
合計ジャッジ時間 10,048 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 63 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    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')

    # Check the case where we only use waiting days (only possible if T is positive)
    if T >= 0:
        min_cost = T

    # Iterate over possible k (forward steps)
    max_iterations = 2 * 10**6
    for k in range(0, max_iterations):
        numerator = k * A - T
        if numerator <= 0:
            m = 0
        else:
            m = (numerator + B - 1) // B
        S = k * A - m * B
        if S > T:
            continue
        cost = k * X + m * Y + (T - S)
        if cost < min_cost:
            min_cost = cost

    # Iterate over possible m (backward steps)
    for m in range(0, max_iterations):
        numerator = m * B + T
        if numerator <= 0:
            k = 0
        else:
            k = (numerator + A - 1) // A
        S = k * A - m * B
        if S > T:
            continue
        cost = k * X + m * Y + (T - S)
        if cost < min_cost:
            min_cost = cost

    print(min_cost)

if __name__ == "__main__":
    main()
0