結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー fumofumofuni
提出日時 2021-03-16 19:43:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,852 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 206,932 KB
最終ジャッジ日時 2025-01-19 17:33:56
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    vl v(3);rep(i,3)cin >> v[i];
    vpl x(3),y(3);
    ll now=0;
    rep(i,3){
        repl(j,i+1,3){
            ll cur=v[i]*v[j],nx=v[i]+v[j],ny=v[j]-v[i];
            ll g1=gcd(cur,nx),g2=gcd(cur,ny);
            //cout << cur/g1 <<" " << nx/g1 <<endl;
            //cout << cur/g2 <<" " << ny/g2 <<endl;
            x[now]={cur/g1,nx/g1};
            y[now]={cur/g2,ny/g2};
            now++;
        }
    }
    vector<pair<long double,pl>> ans;
    rep(bit,1<<3){
        ll p=1,q=0;
        rep(i,3){
            if(bit&(1<<i))p=lcm(p,x[i].fi),q=gcd(q,x[i].se);
            else p=lcm(p,y[i].fi),q=gcd(q,y[i].se);
        }
        ll g=gcd(p,q);
        p/=g,q/=g;
        long double t=p;t/=q;
        ans.push_back({t,{p,q}});
    }
    sort(all(ans));
    cout << ans[0].se.first <<"/" <<ans[0].se.second <<endl;
}   
0