結果

問題 No.3154 convex polygon judge
ユーザー SnowBeenDiding
提出日時 2025-05-20 21:34:21
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,558 bytes
コンパイル時間 5,030 ms
コンパイル使用メモリ 335,740 KB
実行使用メモリ 13,340 KB
最終ジャッジ日時 2025-05-20 21:34:31
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

template <class T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> pts) {
    if (pts.size() <= 1)
        return pts;
    sort(pts.begin(), pts.end());
    pts.erase(unique(pts.begin(), pts.end()), pts.end());
    if (pts.size() <= 2)
        return pts;
    auto cross = [](auto const &a, auto const &b, auto const &c) {
        return (b.first - a.first) * (c.second - a.second) -
               (b.second - a.second) * (c.first - a.first);
    };
    vector<pair<T, T>> hull;
    hull.reserve(pts.size() * 2);
    for (auto const &p : pts) {
        while (hull.size() >= 2 &&
               cross(hull[hull.size() - 2], hull[hull.size() - 1], p) <= 0) {
            hull.pop_back();
        }
        hull.push_back(p);
    }
    size_t lower_size = hull.size();
    for (auto it = pts.rbegin(); it != pts.rend(); ++it) {
        while (hull.size() >= lower_size + 1 &&
               cross(hull[hull.size() - 2], hull[hull.size() - 1], *it) <= 0) {
            hull.pop_back();
        }
        hull.push_back(*it);
    }
    hull.pop_back();
    return hull;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        p[i] = {x, y};
    }
    auto v = ConvexHull(p);
    bool ok = v.size() == n;
    cout << (ok ? "Yes\n" : "No\n");
}
0