結果

問題 No.3154 convex polygon judge
ユーザー iomir
提出日時 2025-05-22 21:51:11
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 2,010 bytes
コンパイル時間 3,243 ms
コンパイル使用メモリ 293,936 KB
実行使用メモリ 17,556 KB
最終ジャッジ日時 2025-05-22 21:51:17
合計ジャッジ時間 6,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using lll = __int128;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;
//using mint=modint1000000007;
//using mint=modint998244353;

const ll INF=1ll<<60;
ll mod10=1e9+7;
ll mod99=998244353;
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=a;i>=n;--i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }


vp convexhull(vll& X,vll& Y){
    ll N = X.size();
    vp XY(N);rep(i,N) XY[i]={Y[i],X[i]};
    sort(all(XY));
    for(auto& [a,b]:XY) swap(a,b);
    per(i,N){
        XY[i].first-=XY[0].first;
        XY[i].second-=XY[0].second;
    }
    vll ind(N);rep(i,N) ind[i]=i;
    auto f = [&](P A,P B){
        ll ax=A.first,ay=A.second;
        ll bx=B.first,by=B.second;
        ll areaa=!((ay>0)||(ay==0&&ax>=0));
        ll areab=!(by>0||(by==0&&bx>=0));
            
        return (areaa==areab?ax*by-ay*bx>0:areaa<areab);
            
    };
    sort(all(XY),f);
    vll ans={0,1};
    rep2(i,2,N){
        ll k=ans[ans.size()-2],j=ans[ans.size()-1];
        ll x1=XY[i].first-XY[j].first,y1=XY[i].second-XY[j].second;
        ll x2=XY[k].first-XY[j].first,y2=XY[k].second-XY[j].second;
        if(x1*y2-x2*y1>0) ans.push_back(i);
    }
    vp XY2;
    for(auto i:ans) XY2.emplace_back(XY[i].first,XY[i].second);
    return XY2;
}

bool solve(){
    ll N;cin>>N;
    vll X(N),Y(N);rep(i,N) cin>>X[i]>>Y[i];
    cout<<(convexhull(X,Y).size()==N?"Yes":"No")<<endl;
    return 0;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll T=1;//cin>>T;
    rep(i,T) solve();
}
    
0