結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー srjywrdnprkt
提出日時 2023-06-11 03:31:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 105,456 KB
最終ジャッジ日時 2025-02-14 01:28:17
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    ll T, ans=1e18, x, a, y, b;
    cin >> T;
    cin >> x >> a >> y >> b;

    if (T >= 0){
        for (ll i=0; i<=1e7; i++){
            if (a*i-T >= 0){
                ll j = (a*i-T+b-1)/b;
                ans = min(ans, x*i+y*j+T-(a*i-b*j));
            }
            else ans = min(ans, x*i+T-a*i);
        }
    }
    else{
        for (int i=0; i<=1e7; i++){
            if (T < -b*i) continue;
            ll j = (T+b*i)/a;
            ans = min(ans, y*i+x*j+T+b*i-a*j);
        }
    }

    cout << ans << endl;

    return 0;
}
0