結果

問題 No.3154 convex polygon judge
ユーザー hint908
提出日時 2025-05-20 21:31:24
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 3,516 bytes
コンパイル時間 3,079 ms
コンパイル使用メモリ 287,536 KB
実行使用メモリ 12,824 KB
最終ジャッジ日時 2025-05-20 21:31:31
合計ジャッジ時間 4,777 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘std::vector<std::complex<double> > convex_hull(std::vector<std::complex<double> >&, bool)’:
main.cpp:60:11: warning: capture of variable ‘EPS’ with non-automatic storage duration
   60 |         [&EPS](const Point& a, const Point& b) { return abs(a.X - b.X) > EPS ? a.X < b.X : a.Y < b.Y; });
      |           ^~~
main.cpp:50:14: note: ‘const double EPS’ declared here
   50 | const double EPS = 1e-10;
      |              ^~~

ソースコード

diff #

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")


#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using VVVV = VV<VV<T>>;
#define rep(i,n) for(ll i=0ll;(i)<(n);(i)++)
#define REP(i,a,n) for(ll i=(a);(i)<(n);(i)++)
#define rrep(i,n) for(ll i=(n)-1;(i)>=(0ll);(i)--)
#define RREP(i,a,n) for(ll i=(n)-1;(i)>=(a);(i)--)
const long long INF = (1LL << 60);
const long long mod99 = 998244353;
const long long mod107 = 1000000007;
const long long mod = mod99;
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
#define all(v) (v).begin(),(v).end()
#define foa(i,v) for(auto& (i) : (v))
#define UQ(v) sort(be(v)), (v).erase(unique(be(v)), (v).end())
#define UQ2(v,cmp) sort(be(v)), (v).erase(unique(be(v),cmp), (v).end())
#define UQ3(v,cmp) sort(be(v),cmp), (v).erase(unique(be(v)), (v).end())
#define UQ4(v,cmp,cmp2) sort(be(v), cmp), (v).erase(unique(be(v),cmp2), (v).end())
#define LB(x,v) (lower_bound(be(v),(x))-(v).begin())
#define LB2(x,v,cmp) (lower_bound(be(v),(x),(cmp))-(v).begin())
#define UB(x,v) (upper_bound(be(v),(x))-(v).begin())
#define UB2(x,v,cmp) (upper_bound(be(v),(x),(cmp))-(v).begin())
#define dout()  cout << fixed << setprecision(20)
#define randinit() srand((unsigned)time(NULL))

template<class T, class U> bool chmin(T& t, const U& u) { if (t > u){ t = u; return 1;} return 0; }
template<class T, class U> bool chmax(T& t, const U& u) { if (t < u){ t = u; return 1;} return 0; }


ll Rnd(ll L=0, ll R=mod99){return rand()%(R-L)+L;}

using Point = complex<double>;
using Line = vector<Point>;

#define X real()
#define Y imag()
const double EPS = 1e-10;

inline double dot(const Point& a, const Point& b) { return a.X * b.X + a.Y * b.Y; }
inline double cross(const Point& a, const Point& b) { return a.X * b.Y - a.Y * b.X; }
inline double abs(const Point& a) { return sqrt(dot(a, a)); }

vector<Point> convex_hull(vector<Point>& ps, bool collinear = false) {
   int n = ps.size();
   if(n <= 1) return ps;
   sort(ps.begin(), ps.end(),
        [&EPS](const Point& a, const Point& b) { return abs(a.X - b.X) > EPS ? a.X < b.X : a.Y < b.Y; });
   vector<Point> hull(2 * n);
   double th = collinear ? -EPS : EPS;
   int k = 0;
   for(int i = 0; i < n; i++) {
      if(k >= 2) {
         while(cross(hull[k - 1] - hull[k - 2], ps[i] - hull[k - 2]) < th) {
            k--;
            if(k < 2) break;
         }
      }
      if(k < 1 || abs(hull[k - 1] - ps[i]) > EPS) {
         hull[k] = ps[i];
         k++;
      }
   }
   int t = k + 1;
   for(int i = n - 2; i >= 0; i--) {
      if(k >= t) {
         while(cross(hull[k - 1] - hull[k - 2], ps[i] - hull[k - 2]) < th) {
            k--;
            if(k < t) break;
         }
      }
      if(k < 1 || abs(hull[k - 1] - ps[i]) > EPS) {
         hull[k] = ps[i];
         k++;
      }
   }
   hull.resize(max(1, k - 1));
   return hull;
}


void solve(){
    int N;
    cin >> N;
    vector<Point> ps(N);
    for(int i = 0; i < N; i++) {
     double x, y;
     cin >> x >> y;
     ps[i] = Point(x, y);
    }
    auto ans = convex_hull(ps);
    if(size(ans) == N) cout << "Yes" << endl;
    else cout << "No" << endl;
}





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