結果

問題 No.3154 convex polygon judge
ユーザー Ponzu
提出日時 2025-05-20 22:20:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 3,028 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 138,344 KB
実行使用メモリ 13,692 KB
最終ジャッジ日時 2025-05-20 22:20:07
合計ジャッジ時間 3,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

struct Pos {
  ll x, y;

  bool operator< (const Pos& other) const {
    return (x == other.x ? y < other.y : x < other.x);
  }
};

inline ll cross(Pos &a, Pos &b, Pos &c) {
  return (((b.x - a.x) * (c.y - a.y)) - ((b.y - a.y) * (c.x - a.x)));
}

void convex_hull(vector<Pos> &ps, vector<Pos> &qs) {
  qs.clear();
  qs.reserve(ps.size());
  int n = ps.size();
  for(auto p : ps) {
    while(qs.size() > 1 && cross(qs[qs.size()-2], qs[qs.size()-1], p) > 0) {
      qs.pop_back();
    }
    qs.push_back(p);
  }
  int t = qs.size();

  for(int i = n-2; i >= 0; --i) {
    Pos &p = ps[i];
    while(qs.size() > t && cross(qs[qs.size()-2], qs[qs.size()-1], p) > 0) {
      qs.pop_back();
    }
    qs.push_back(p);
  }
  qs.pop_back();
}

P diff_pair( P p1, P p2 ){              // caculate difference of p1 from p2
    int a = p1.first - p2.first;
    int b = p1.second - p2.second;
    return make_pair(a,b);
}

int signed_area( P p1, P p2, P p3 ){    // to chech relativistic position of 3 poins
    P v1 = diff_pair( p2,p1 );
    P v2 = diff_pair( p3,p1 );
    return v1.first*v2.second - v1.second*v2.first;    // calc area as z-component of v1 x v2
}


int main() {
  int n;
  vector<Pos> ps, qs;
  cin >> n;
  rep(i, n) {
    int x, y; cin >> x >> y;
    ps.emplace_back(Pos{y, x});
  }
  sort(ALL(ps));
  convex_hull(ps, qs);
  //cout << qs.size() << endl;
  string ans = "Yes";
  if(n != qs.size()) {
	cout << "No" << endl;
	return 0;
  }
  for(int i=1;i<qs.size()-1;++i){
	long long S = signed_area(P(qs[i-1].x,qs[i-1].y),P(qs[i].x,qs[i].y),P(qs[i+1].x,qs[i+1].y));
	if(S==0){
		cout << "No" << endl;
		return 0;
	}

  }
  cout << ans << endl;
  return 0;
}
0