結果

問題 No.176 2種類の切手
ユーザー cormorancormoran
提出日時 2016-10-04 18:31:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 1,000 ms
コード長 1,331 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 168,172 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 11:54:33
合計ジャッジ時間 4,574 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
6,816 KB
testcase_01 AC 226 ms
6,940 KB
testcase_02 AC 33 ms
6,940 KB
testcase_03 AC 29 ms
6,944 KB
testcase_04 AC 29 ms
6,940 KB
testcase_05 AC 28 ms
6,940 KB
testcase_06 AC 29 ms
6,940 KB
testcase_07 AC 28 ms
6,940 KB
testcase_08 AC 29 ms
6,944 KB
testcase_09 AC 28 ms
6,944 KB
testcase_10 AC 29 ms
6,940 KB
testcase_11 AC 29 ms
6,940 KB
testcase_12 AC 29 ms
6,944 KB
testcase_13 AC 30 ms
6,944 KB
testcase_14 AC 28 ms
6,940 KB
testcase_15 AC 29 ms
6,944 KB
testcase_16 AC 28 ms
6,944 KB
testcase_17 AC 29 ms
6,940 KB
testcase_18 AC 28 ms
6,948 KB
testcase_19 AC 28 ms
6,944 KB
testcase_20 AC 30 ms
6,940 KB
testcase_21 AC 219 ms
6,944 KB
testcase_22 AC 225 ms
6,944 KB
testcase_23 AC 216 ms
6,940 KB
testcase_24 AC 29 ms
6,940 KB
testcase_25 AC 29 ms
6,940 KB
testcase_26 AC 222 ms
6,944 KB
testcase_27 AC 30 ms
6,940 KB
testcase_28 AC 29 ms
6,940 KB
testcase_29 AC 31 ms
6,944 KB
testcase_30 AC 29 ms
6,940 KB
testcase_31 AC 125 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;

template<typename T>
T gcd(T a,T b){
    T c=a,d=b,r;
    do{r=c%d;c=d;d=r;}while(r);
    return c;
}

template<typename T>
T lcm(T a,T b){return a*b/gcd(a,b);}

class Solver {
  public:

    ll trial(ll A, ll B, ll T) {
        ll mini = INFL;        
        rep(k, 2) {
            if(k != 0) swap(A, B);
            rep(i, 10000000) {
                if(A * i >= T) {
                    set_min(mini, A * i);
                } else {                
                    ll j = (T - A * i) / B;                
                    while(A * i + B * j < T) j++;                
                    set_min(mini, A * i + B * j);
                }
            }
        }
        return mini;
    }
    
    bool solve() {
        ll A, B, T; cin >> A >> B >> T;
        ll ans = trial(A, B, T);
        
        ll ans2 = (T / (A * B)) * A * B;
        T %= A * B;
        ans2 += trial(A, B, T);        

        cout << min(ans, ans2) << endl;
        
        return 0;
    }
};

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