結果
| 問題 |
No.3154 convex polygon judge
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-20 23:15:38 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,096 bytes |
| コンパイル時間 | 6,946 ms |
| コンパイル使用メモリ | 334,116 KB |
| 実行使用メモリ | 10,660 KB |
| 最終ジャッジ日時 | 2025-05-20 23:15:47 |
| 合計ジャッジ時間 | 8,058 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 42 WA * 2 |
ソースコード
#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;
}