結果

問題 No.2099 [Cherry Alpha B] Time Machine
コンテスト
ユーザー LyricalMaestro
提出日時 2025-05-01 14:34:19
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 778 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 229 ms
コンパイル使用メモリ 96,104 KB
実行使用メモリ 766,944 KB
最終ジャッジ日時 2026-07-10 10:06:18
合計ジャッジ時間 50,770 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50 TLE * 1 MLE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2099


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

    # yが取りうる最小値を取得
    if T >= 0:
        y_min = 0
    else:
        y_min = (- T) // B + (1 if (-T) % B > 0 else 0)

    # 本処理
    t_map = {}
    t = (T + y_min * B) % A
    cost = y_min
    while t not in t_map:
        t_map[t] = cost
        cost += 1
        t += B
        t %= A
    
    min_answer = float("inf")
    for t, cost in t_map.items():
        xx = T + cost * B
        answer = cost * Y + t
        xx0 = xx - t
        a = xx0 // A
        answer += a * X

        min_answer = min(min_answer, answer)
    print(min_answer)

    


    



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