結果
| 問題 |
No.176 2種類の切手
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-10-04 17:54:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,468 bytes |
| コンパイル時間 | 1,889 ms |
| コンパイル使用メモリ | 165,964 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 15:54:51 |
| 合計ジャッジ時間 | 2,930 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 2 |
ソースコード
#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;
return (R / x + 1) * x;
}
void solve() {
if (A < B) swap(A, B);
ll L = lcm(A, B);
ll ans = min(calc(T, A), calc(T, B));
ll R = T / L * L;
T = T % L;
for (ll i = 0; i * A <= T + A; i++) {
ans = min(ans, R + i * A + calc(T - i * A, B));
}
for (ll i = 0; i * B <= T + B; i++) {
ans = min(ans, R + i * B + calc(T - i * B, A));
}
cout << ans << endl;
}
}
int main() {
input(); solve();
return 0;
}
izuru_matsuura