結果

問題 No.176 2種類の切手
ユーザー kimiyukikimiyuki
提出日時 2016-10-04 18:00:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,280 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 83,656 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-05-01 11:43:21
合計ジャッジ時間 5,640 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <set>
#include <queue>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <typename T> T gcd(T a, T b) { while (a) { b %= a; swap(a, b); } return b; }
const int inf = 1e9+7;
int main() {
    int a, b, t; cin >> a >> b >> t;
    int d = gcd(gcd(a, b), t);
    a /= d;
    b /= d;
    t /= d;
    int ans = inf;
    if (b < 100) {
        set<int> used;
        reversed_priority_queue<int> que;
        que.push(0);
        while (not que.empty()) {
            int i = que.top(); que.pop();
            used.erase(i);
            if (i >= t) { ans = i; break; }
            if ((t - i) % a == 0) { ans = t; break; }
            if ((t - i) % b == 0) { ans = t; break; }
            if (not used.count(i + a)) { used.insert(i + a); que.push(i + a); }
            if (not used.count(i + b)) { used.insert(i + b); que.push(i + b); }
        }
    } else {
        assert (false);
        for (int i = 0; i <= t; i += b) {
            setmin(ans, i + (t - i + a-1) / a * a);
        }
    }
    cout << ans * d << endl;
    return 0;
}
0