結果

問題 No.176 2種類の切手
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-04 17:49:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,599 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 166,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 11:42:35
合計ジャッジ時間 2,921 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    ll A, B, T;
    void input() {
        cin >> A >> B >> T;
    }

    ll gcd(ll a, ll b) {
        if (a > b) swap(a, b);
        if (b % a == 0) return b;
        return gcd(b % a, a);
    }
    ll lcm(ll a, ll b) {
        ll g = gcd(a, b);
        return a / g * b;
    }

    const ll INF = 1LL<<56;

    ll calc(ll R, ll x) {
        if (R <= 0) return 0;
        if (R % x == 0) return R;
        return (R / x + 1) * x;
    }

    void solve() {
        if (A < B) swap(A, B);
        ll L = lcm(A, B);
        ll ans = min(calc(T, A), calc(T, B));
        if (T < L) {
            for (ll i = 0; i * A <= T; i++) {
                ans = min(ans, i * A + calc(T - i * A, B));
            }
            for (ll i = 0; i * B <= T; i++) {
                ans = min(ans, i * B + calc(T - i * B, A));
            }
        } else {
            for (ll i = 0; i * A <= L; i++) {
                ans = min(ans, i * A + calc(T - i * A, B));
            }
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0