結果
問題 | No.176 2種類の切手 |
ユーザー |
![]() |
提出日時 | 2015-04-03 01:30:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 10 ms / 1,000 ms |
コード長 | 1,897 bytes |
コンパイル時間 | 645 ms |
コンパイル使用メモリ | 75,028 KB |
実行使用メモリ | 10,544 KB |
最終ジャッジ日時 | 2024-10-08 02:54:01 |
合計ジャッジ時間 | 1,853 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#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; }