結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー ctyl_0ctyl_0
提出日時 2015-09-15 18:08:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,413 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 85,552 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 12:05:14
合計ジャッジ時間 3,235 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0