結果

問題 No.176 2種類の切手
ユーザー yosupotyosupot
提出日時 2015-04-03 01:30:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 1,897 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 75,284 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-16 21:59:58
合計ジャッジ時間 1,808 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <cstdio>
#include <bitset>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

/**
 * Dijkstra法により最短距離を求める
 *
 * template引数のint Vは頂点数
 */
template<int V>
struct Dijkstra {
    typedef int T; /// 辺の距離の型
    const int INF = 1e9;
    typedef pair<T, int> P;
    vector<P> g[V];
    /// 辺のクリア
    void init() {
        for (int i = 0; i < V; i++) {
            g[i].clear();
        }
    }
    /// 辺の追加
    void add(int from, int to, T dist) {
        g[from].push_back(P(dist, to));
    }
    T res[V]; /// execを行うと、これに最短距離が入る 
    void exec(int s) {
        fill_n(res, V, INF);
        priority_queue<P, vector<P>, greater<P>> q;
        q.push(P(0, s));
        res[s] = 0;
        while (!q.empty()) {
            P p = q.top(); q.pop();
            if (res[p.second] < p.first) continue;
            for (P e: g[p.second]) {
                if (p.first+e.first < res[e.second]) {
                    res[e.second] = p.first+e.first;
                    q.push(P(e.first+p.first, e.second));
                }
            }
        }
        return;
    }
};


Dijkstra<200000> djk;

int main() {
    ll res = 1LL<<55;
    ll a, b, t;
    cin >> a >> b >> t;
    if (b < 100000) {
        for (int i = 0; i < b; i++) {
            djk.add(i, (i+a)%b, 1);
        }
        djk.exec(0);
        for (int i = 0; i < b; i++) {
            ll aa = a*djk.res[i];
            res = min(res, max(0LL, (t-aa+b-1)/b)*b+aa);
        }
    } else {
        for (int i = 0; i < 100000; i++) {
            ll bb = b*i;
            res = min(res, max(0LL, (t-bb+a-1)/a)*a+bb);
        }
    }
    cout << res << endl;
    return 0;
}
0