結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const ll MOD = 998244353;
const double INFD = 1.0E18;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
//const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using Pair = pair<ll, ll>;
using Graph = vector<vector<pair<int, int>>>;
using mint = atcoder::modint998244353;



vector<pair<ll, ll>> get_convex_hull(vector<pair<ll, ll>>& points){
    sort(points.begin(), points.end());
    points.erase(unique(begin(points), end(points)), end(points));
    int n = points.size();
    int k = 0; //size of convexfull
    if (n <= 2) return points;
    vector<pair<ll, ll>> ch;
    auto det = [&](pair<ll, ll> p, pair<ll, ll> q){
        return p.first * q.second - q.first * p.second;
    };
    
    auto sub = [&](pair<ll, ll> p, pair<ll, ll> q){
        return make_pair(p.first - q.first, p.second - q.second);
    };
    
    //反時計回り
    for (int i = 0; i < n; i++){
        while (k > 1){
            pair<ll, ll> v_cur = sub(ch[k - 1], ch[k - 2]);
            pair<ll, ll> v_new = sub(points[i], ch[k - 2]);
            if (det(v_cur, v_new) > 0) break;
            k--;
            ch.pop_back();
        }
        ch.push_back(points[i]);
        k++;
    }
    
    int t = ch.size();
    for (int i = n - 2; i >= 0; i--){
        while (k > t){
            pair<ll, ll> v_cur = sub(ch[k - 1], ch[k - 2]);
            pair<ll, ll> v_new = sub(points[i], ch[k - 2]);
            if (det(v_cur, v_new) > 0) break;
            k--;
            ch.pop_back();
        }
        ch.push_back(points[i]);
        k++;
    }
    ch.resize(k - 1);
    return ch;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    ll n; cin >> n;
    vector<pair<ll, ll>> points(n);
    for (auto &[x, y] : points) cin >> x >> y;
    auto ch = get_convex_hull(points);
    cout << (ch.size() == n ? "Yes" : "No") << endl;
    
    return 0;
}
0