結果

問題 No.3005 トレミーの問題
ユーザー umimel
提出日時 2025-01-17 23:05:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 168,936 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-17 23:06:07
合計ジャッジ時間 2,580 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 2;


ll dist(pair<ll, ll> x, pair<ll, ll> y){
    return (x.fi-y.fi)*(x.fi-y.fi) + (x.se-y.se)*(x.se-y.se);
}

ll pow2(ll n){
    return n*n;
}

void solve(){
    vector<pair<ll, ll>> P(4);
    for(int i=0; i<4; i++) cin >> P[i].fi >> P[i].se;

    {//凸包構築
        sort(all(P));
        vector<pair<ll, ll>> U, L;
        for(int i=0; i<4; i++){
            while(U.size() >= 2 && (U[U.size()-1].fi-U[U.size()-2].fi)*(P[i].se-U[U.size()-2].se) <= (P[i].fi-U[U.size()-2].fi)*(U[U.size()-1].se-U[U.size()-2].se)) U.pop_back();
            while(L.size() >= 2 && (L[L.size()-1].fi-L[L.size()-2].fi)*(P[i].se-L[L.size()-2].se) >= (P[i].fi-L[L.size()-2].fi)*(L[L.size()-1].se-L[L.size()-2].se)) L.pop_back();
            U.pb(P[i]);
            L.pb(P[i]);
        }
        P.clear();
        for(int i=0; i<U.size(); i++) P.pb(U[i]);
        for(int i=L.size()-2; i>0; i--) P.pb(L[i]);
    }

    if((int)P.size() != 4){
        cout << "NO\n";
        return;
    }

    ll ab = dist(P[0], P[1]);
    ll cd = dist(P[2], P[3]);
    ll ad = dist(P[0], P[3]);
    ll bc = dist(P[1], P[2]);
    ll ac = dist(P[0], P[2]);
    ll bd = dist(P[1], P[3]);

    if(4LL*ab*cd*ad*bc == pow2(ac*bd-ab*cd-ad*bc)){
        cout << "YES\n";
        return;
    }

    cout << "NO\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    //cin >> T;
    while(T--) solve();
}
0