結果

問題 No.176 2種類の切手
ユーザー cormorancormoran
提出日時 2016-10-04 17:50:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,168 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 159,572 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 11:42:45
合計ジャッジ時間 9,585 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 422 ms
6,940 KB
testcase_02 AC 224 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 224 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 224 ms
6,944 KB
testcase_21 AC 225 ms
6,940 KB
testcase_22 AC 224 ms
6,944 KB
testcase_23 AC 224 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 224 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 223 ms
6,940 KB
testcase_30 WA -
testcase_31 AC 223 ms
6,944 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:
    bool solve() {
        ll A, B, T; cin >> A >> B >> T;
        ll ans = 0;
        ll lc = lcm(A, B);
        ans += (T / lc) * lc;
        T %= lc;

        ll mini = INFL;
        rep(k, 2) {
            if(k != 0) swap(A, B);
            rep(i, 10000000) {   
                if(A * i >= 0) { // overflow 対策
                    ll j = T  >= A * i ? 0 :  (T - A * i) / B;
                    while(A * i + B * j < T) j++;
                    set_min(mini, A * i + B * j);
                }
            }
        }
        
        assert(mini < INFL);
        cout << ans + mini << endl;
        
        return 0;
    }
};

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