結果
| 問題 |
No.229 線分上を往復する3つの動点の一致
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-15 18:08:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,413 bytes |
| コンパイル時間 | 701 ms |
| コンパイル使用メモリ | 89,556 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 06:37:09 |
| 合計ジャッジ時間 | 1,779 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
int inputValue(){
int a;
cin >> a;
return a;
};
void inputArray(int * p, int a){
rep(i, a){
cin >> p[i];
}
};
void inputVector(vector<int> * p, int a){
rep(i, a){
int input;
cin >> input;
p -> push_back(input);
}
}
template <typename T>
void output(T a, int precision) {
if(precision > 0){
cout << setprecision(precision) << a << "\n";
}
else{
cout << a << "\n";
}
}
// a < b
ll gcd(ll a, ll b){
if (a > b) {
swap(a, b);
}
if (b % a == 0) {
return a;
}
else{
ll g = b % a;
return gcd(g, a);
}
}
// a < b
ll lcm(ll a, ll b){
return (ll)a * ((ll)b / (ll)gcd(a, b));
}
// first:分子 second:分母
// x = 6 / 5, y = 4 / 3: return: 12 / 1
pair<ll, ll> smallest(pair<ll, ll> x, pair<ll, ll> y){
pair<ll, ll> ret;
ret.second = lcm(x.second, y.second);
ret.first = lcm(x.first * (ret.second / x.second), y.first * (ret.second / y.second));
ll g = gcd(ret.first, ret.second);
ret.first /= g;
ret.second /= g;
return ret;
}
// T1 < T2 < T3
pair<ll, ll> sml(vector<ll> T, bool s1, bool s2){
pair<ll, ll> ret;
ret.first = T[0] * T[1] * T[2];
ll S1 = (s1 == true) ? T[1] + T[0] : T[1] - T[0];
ll S2 = (s2 == true) ? T[2] + T[0] : T[2] - T[0];
ret.second = gcd(T[2] * S1, T[1] * S2);
ll g = gcd(ret.first, ret.second);
ret.first /= g;
ret.second /= g;
return ret;
}
int main(int argc, const char * argv[]) {
// source code
vector<ll> T(3);
rep(i, 3){
T[i] = (ll)inputValue();
}
sort(T.begin(), T.end());
vector<pair<ll, ll> > M(4);
M[0] = sml(T, true, true);
M[1] = sml(T, true, false);
M[2] = sml(T, false, true);
M[3] = sml(T, false, false);
pair<ll, ll> ret = M[0];
rep(i, 4){
if (ret.first * M[i].second > ret.second * M[i].first ) {
ret = M[i];
}
}
cout << ret.first << "/" << ret.second << endl;
return 0;
}