結果
問題 |
No.3154 convex polygon judge
|
ユーザー |
![]() |
提出日時 | 2025-05-20 22:09:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 71 ms / 2,000 ms |
コード長 | 2,539 bytes |
コンパイル時間 | 3,107 ms |
コンパイル使用メモリ | 288,716 KB |
実行使用メモリ | 17,428 KB |
最終ジャッジ日時 | 2025-05-20 22:09:08 |
合計ジャッジ時間 | 5,160 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n) - 1; i >= 0; --i) #define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template<class T> std::vector<std::pair<T, T>>convex_hull(std::vector<std::pair<T, T>>V) { // 注意!! // 同一直線上の三点を含む、除きたいときは >=にする std::sort(V.begin(), V.end()); int n = V.size(); std::vector<std::pair<T, T>>X; int k = 0; for (int i = 0; i < n; ++i) { while ((k >= 2) && ((V[i].first - X[k - 2].first)*(X[k - 1].second - X[k - 2].second) >= (V[i].second - X[k - 2].second)*(X[k - 1].first - X[k - 2].first))) { X.pop_back(); k--; } X.push_back(V[i]); k++; } std::vector<std::pair<double, double>>Y; int l = 0; for (int i = n - 1; i >= 0; --i) { while ((l >= 2) && ((V[i].first - Y[l - 2].first)*(Y[l - 1].second - Y[l - 2].second) >= (V[i].second - Y[l - 2].second)*(Y[l - 1].first - Y[l - 2].first))) { Y.pop_back(); l--; } Y.push_back(V[i]); l++; } std::vector<std::pair<T, T>>d; for (int i = 0; i < (int)X.size(); ++i)d.push_back(X[i]); for (int i = 1; i < (int)Y.size() - 1; ++i)d.push_back(Y[i]); return d; //周りの長さを返す /*double ret = 0; for (int i = 0; i < X.size() - 1; ++i) { ret += sqrt((X[i + 1].first - X[i].first)*(X[i + 1].first - X[i].first) + (X[i + 1].second - X[i].second)*(X[i + 1].second - X[i].second)); } for (int i = 0; i < Y.size() - 1; ++i) { ret += sqrt((Y[i + 1].first - Y[i].first)*(Y[i + 1].first - Y[i].first) + (Y[i + 1].second - Y[i].second)*(Y[i + 1].second - Y[i].second)); } return ret;*/ } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<long long, long long>>a(n); rep(i, n)cin >> a[i].first >> a[i].second; auto x = convex_hull(a); if (x.size() == n)cout << "Yes" << endl; else cout << "No" << endl; return 0; }