結果
問題 |
No.3154 convex polygon judge
|
ユーザー |
|
提出日時 | 2025-05-20 22:30:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 208 ms / 2,000 ms |
コード長 | 2,488 bytes |
コンパイル時間 | 2,406 ms |
コンパイル使用メモリ | 204,528 KB |
実行使用メモリ | 9,284 KB |
最終ジャッジ日時 | 2025-05-20 22:30:52 |
合計ジャッジ時間 | 4,782 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main(){ ll n; cin>>n; vector<point> v(n); rep(i,n) { cin>>v[i].x>>v[i].y; } ll lowidx=0; srep(i,1,n-1) { if(v[i].y<v[lowidx].y || (v[i].y==v[lowidx].y && v[i].x<v[lowidx].x)) lowidx=i; } swap(v[0],v[lowidx]); point base=v[0]; sort(v.begin()+1,v.end(),[&](point& a,point& b) { ll cross=Xprod(base,a,b); if(cross!=0) return cross>0; return distsq(base,a)<distsq(base,b); } ); vector<point> st; st.reserve(n); st.pb(v[0]); st.pb(v[1]); srep(i,2,n-1) { while(st.size()>=2 && Xprod(st[st.size()-2],st.back(),v[i])<=0) st.pop_back(); st.pb(v[i]); } yn(st.size()==n); } /////// library zone /////// #else #include <bits/stdc++.h> #include <atcoder/segtree> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define srep(i,l,r) for(ll i=l;i<=r;i++) using ll = long long; using ld = long double; const ll mod=998244353; #define vout(v) for(auto i :v) cout<<i<<" "; #define INF 9223300000000000000ll #define Winf 5e12 #define nl "\n" #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define vl vector<ll> #define vc vector<char> #define pb push_back struct point { ll x; ll y; }; ll Xprod(point &o,point &a,point &b) { return (a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x); } ll distsq(const point& a,const point& b){ ll dx=a.x-b.x, dy=a.y-b.y; return dx*dx+dy*dy; } template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} void no() { cout<<"No"<<nl;} void yes() { cout<<"Yes"<<nl;} void yn(bool a) { cout<<(a ? "Yes":"No")<<nl; } ll sum(vector<ll>& a) { ll ans=0; for(auto i:a) ans+=i; return ans; } ll modpow(ll fl, ll po, ll mode) { // mode: 0=modなし, 1=modあり ll ret=1; if (mode) { while (po>0) { if (po&1) ret=(ret*fl)%mod; fl=(fl*fl)%mod; po>>=1; } } else { while (po>0) { if(po&1) ret*=fl; fl*=fl; po>>=1; } } return ret; } ll modinv(ll a, ll mod) { //拡張Euclidによるmodでの逆元, a*u+mod*v=1を解く ll b=mod,u=1,v=0; while (b) { ll t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } u%=mod; if (u < 0) u+=mod; return u; } #endif