結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー a9ua1i0n
提出日時 2022-10-14 22:06:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,528 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 158,448 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-26 14:44:16
合計ジャッジ時間 13,083 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#if !__INCLUDE_LEVEL__
    #include __FILE__

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll T, X, A, Y, B;
    cin >> T >> X >> A >> Y >> B;

    bool is_back = T < 0;
    if (T < 0) {
        T *= -1;
        swap(X, Y);
        swap(A, B);
    }
    // B *= -1;

    if ((!is_back) && X >= A) {
        cout << T << "\n";
        return 0;
    }

    ll TT = T % A;
    ll ans = T / A * X;
    cerr << ans << "\n";
    ll add_cost = is_back ? 1e14 : TT;
    REP(i, 1e7) {
        if (i == 0)
            continue;
        ll cost = X * i;
        if ((A * i - TT) % B == 0) {
            cost += Y * (A * i - TT) / B;
        } else {
            cost += Y * ((A * i - TT) / B) + ((A * i - TT) % B);
        }
        add_cost = min(add_cost, cost);
    }

    cout << ans + add_cost << "\n";

    return 0;
}

//====================temp====================
#else
    #include <bits/stdc++.h>
using namespace std;
    #define REP(i, n) for (int i = 0; i < (int)(n); i++)
    #define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
    #define REPITR(itr, ARRAY) \
        for (auto itr = (ARRAY).begin(); itr != (ARRAY).end(); ++itr)
    #define RREPITR(itr, ARRAY) \
        for (auto itr = (ARRAY).rbegin(); itr != (ARRAY).rend(); ++itr)
    #define ALL(n) (n).begin(), (n).end()
using ll = long long;
using ull = unsigned long long;
//#define int long long
template<typename T> struct edge {
    int to;
    T cost;
    edge() {}
    edge(int to, T cost): to(to), cost(cost) {}
};
#endif
0