結果

問題 No.176 2種類の切手
ユーザー cormorancormoran
提出日時 2016-10-04 20:03:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,313 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 167,120 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 12:19:49
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 WA -
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }

const ll INFL = 1LL << 60;

class Solver {
  public:

    bool solve() {
        ll A, B, T; cin >> A >> B >> T;
        if(A < B) swap(A, B);
        // min_{i, j}(A * i + B * j) sub.to T <= A * i + B * j
        // A >= B とする
        // j = (T - A * i) / B (+1) となる
        // i >= B なら jを増やしてiを減らせるので, i < B だけ見ればいい (i = B + k として, A * i + B * j = A * k + B *(A + j))
        // B が大きい(10^7 ~ くらい)の時、i を全探索できない
        // が、A >= B より A > 10^7 くらいで、 T <= 10^9 より、 i < 10^2 くらいで済む
        //
        // A * i <= T and i < B を満たす最大のiまでiを全部見ていけばいい
        //
        ll res = INFL;
        rep(i, min(T / A, B)) {
            ll j = (T - A * i - 1) / B;
            while(A * i + B * j < T) j++;            
            set_min(res, A * i + B * j);
        }

        cout << res << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0