結果
問題 |
No.3154 convex polygon judge
|
ユーザー |
👑 ![]() |
提出日時 | 2025-05-20 21:25:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 84 ms / 2,000 ms |
コード長 | 3,578 bytes |
コンパイル時間 | 839 ms |
コンパイル使用メモリ | 86,164 KB |
実行使用メモリ | 11,364 KB |
最終ジャッジ日時 | 2025-05-20 21:25:24 |
合計ジャッジ時間 | 2,740 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
#ifdef NACHIA #define _GLIBCXX_DEBUG #else #define NDEBUG #endif #include <iostream> #include <string> #include <vector> #include <algorithm> using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(i64 i=0; i<i64(n); i++) const i64 INF = 1001001001001001001; template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; } template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; } using namespace std; #include <utility> namespace nachia{ template<class Int = long long, class Int2 = long long> struct VecI2 { Int x, y; VecI2() : x(0), y(0) {} VecI2(std::pair<Int, Int> _p) : x(std::move(_p.first)), y(std::move(_p.second)) {} VecI2(Int _x, Int _y) : x(std::move(_x)), y(std::move(_y)) {} VecI2& operator+=(VecI2 r){ x+=r.x; y+=r.y; return *this; } VecI2& operator-=(VecI2 r){ x-=r.x; y-=r.y; return *this; } VecI2& operator*=(Int r){ x*=r; y*=r; return *this; } VecI2 operator+(VecI2 r) const { return VecI2(x+r.x, y+r.y); } VecI2 operator-(VecI2 r) const { return VecI2(x-r.x, y-r.y); } VecI2 operator*(Int r) const { return VecI2(x*r, y*r); } VecI2 operator-() const { return VecI2(-x, -y); } Int2 operator*(VecI2 r) const { return Int2(x) * Int2(r.x) + Int2(y) * Int2(r.y); } Int2 operator^(VecI2 r) const { return Int2(x) * Int2(r.y) - Int2(y) * Int2(r.x); } bool operator<(VecI2 r) const { return x < r.x || (!(r.x < x) && y < r.y); } Int2 norm() const { return Int2(x) * Int2(x) + Int2(y) * Int2(y); } Int2 manhattan() const { return std::abs(x) + std::abs(y); } static bool compareYX(VecI2 a, VecI2 b){ return a.y < b.y || (!(b.y < a.y) && a.x < b.x); } static bool compareXY(VecI2 a, VecI2 b){ return a.x < b.x || (!(b.x < a.x) && a.y < b.y); } bool operator==(VecI2 r) const { return x == r.x && y == r.y; } bool operator!=(VecI2 r) const { return x != r.x || y != r.y; } }; } // namespace nachia namespace nachia{ // border = true is buggy template<class Int, class Int2> std::vector<int> convexHull(std::vector<VecI2<Int, Int2>> points, bool border = false) { int n = points.size(); if(n == 0) return {}; std::vector<int> ord(n); for(int i=0; i<n; i++) ord[i] = i; std::sort(ord.begin(), ord.end(), [&](int l, int r) -> bool { if(points[l].x != points[r].x) return points[l].x < points[r].x; return points[l].y < points[r].y; }); if(points[ord.front()] == points[ord.back()]){ return std::vector<int>(1,0); } std::vector<int> res; int ressz = 0; for(int t=0; t<2; t++){ for(int p : ord){ Int2 x0 = points[p].x, y0 = points[p].y; while(ressz + 2 <= (int)res.size()){ int q = res.back(); Int2 x1 = points[q].x - x0, y1 = points[q].y - y0; res.pop_back(); Int2 x2 = points[res.back()].x - x0, y2 = points[res.back()].y - y0; if(border ? (x1 * y2 > x2 * y1) : (x1 * y2 >= x2 * y1)) continue; res.push_back(q); break; } res.push_back(p); } if(t == 0) std::reverse(ord.begin(), ord.end()); res.pop_back(); ressz = res.size(); } return res; } } // namespace nachia void testcase(){ i64 N; cin >> N; auto vs = vector<nachia::VecI2<>>(N); for(auto& [x,y] : vs) cin >> x >> y; auto ch = nachia::convexHull(vs); cout << (ch.size() == N ? "Yes\n" : "No\n"); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }