結果
問題 |
No.176 2種類の切手
|
ユーザー |
![]() |
提出日時 | 2016-10-04 17:33:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,261 bytes |
コンパイル時間 | 1,419 ms |
コンパイル使用メモリ | 167,684 KB |
実行使用メモリ | 10,020 KB |
最終ジャッジ日時 | 2024-11-21 15:41:52 |
合計ジャッジ時間 | 7,739 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 WA * 4 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() { ll L = lcm(A, B); ll ans = INF; for (int i = 0; i * A <= L; i++) { ans = min(ans, i * A + calc(T - i * A, B)); } cout << ans << endl; } } int main() { input(); solve(); return 0; }