結果

問題 No.176 2種類の切手
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-10-04 17:43:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,459 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 167,564 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-05-01 11:42:17
合計ジャッジ時間 4,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 238 ms
13,752 KB
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;

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;
        ll y = x - R % x;
        return R + y;
    }

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

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

0