結果
問題 |
No.176 2種類の切手
|
ユーザー |
![]() |
提出日時 | 2016-10-04 17:43:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,459 bytes |
コンパイル時間 | 1,437 ms |
コンパイル使用メモリ | 167,628 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-11-21 15:54:04 |
合計ジャッジ時間 | 4,830 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 WA * 1 TLE * 1 |
ソースコード
#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; }