結果

問題 No.176 2種類の切手
ユーザー cormorancormoran
提出日時 2016-10-04 20:02:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,284 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 166,496 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-05-01 12:19:20
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;

        // 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