結果
問題 |
No.3154 convex polygon judge
|
ユーザー |
![]() |
提出日時 | 2025-05-20 22:38:45 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,478 bytes |
コンパイル時間 | 6,433 ms |
コンパイル使用メモリ | 334,112 KB |
実行使用メモリ | 20,072 KB |
最終ジャッジ日時 | 2025-05-20 22:38:56 |
合計ジャッジ時間 | 9,863 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 WA * 14 RE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll = long long; using mint = modint998244353; int N; ll X[2 << 17]; ll Y[2 << 17]; ll ccw(int i, int j, int k) { ll xi = X[i] - X[j]; ll yi = Y[i] - Y[j]; ll xk = X[k] - X[j]; ll yk = Y[k] - Y[j]; ll cross = xk * yi - yk * xi; return cross == 0 ? 0 : cross / abs(cross); } ll dist(int i, int j) { ll xi = X[i] - X[j]; ll yi = Y[i] - Y[j]; return xi * xi + yi * yi; } pair<ll, ll> tan(int i, int j) { ll dx = X[j] - X[i]; ll dy = Y[j] - Y[i]; ll g = gcd(dx, dy); return make_pair(dx / g, dy / g); } int find_pivot() { vector<int> P(N); iota(P.begin(), P.end(), 0); auto it = min_element(P.begin(), P.end(), [&](int i, int j) { return X[i] == X[j] ? i < j : X[i] < X[j]; }); return it - P.begin(); } int main() { cin >> N; for(int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } const int k = find_pivot(); map<pair<ll, ll>, int> cnt_tan; for(int i = 0; i < N; i++) { if(i == k) continue; cnt_tan[tan(k, i)]++; } set<pair<ll, ll>> st_many; for(auto [t, c] : cnt_tan) { if(c >= 2) st_many.insert(t); } if(ssize(cnt_tan) <= 1) { cout << "Yes" << endl; return 0; }else if(ssize(st_many) >= 1) { cout << "No" << endl; return 0; } vector<int> P(N); iota(P.begin(), P.end(), 0); P.erase(P.begin() + k); sort(P.begin(), P.end(), [&](int i, int j) { ll res = ccw(i, k, j); ll di = dist(k, i); ll dj = dist(k, j); return res == 0 ? di < dj : res; }); if(ssize(st_many) == 1) { auto t = *st_many.begin(); auto tf = tan(k, P.front()); auto tb = tan(k, P.back()); cout << (t == tf) << endl; if(t == tb) { int x = N; while(x > 0 && tan(k, P[x - 1]) == t) x--; reverse(P.begin() + x, P.end()); }else if(t != tf) { cout << "No" << endl; return 0; } }else if(ssize(st_many) == 2) { auto t1 = *st_many.begin(); auto t2 = *st_many.rbegin(); auto tf = tan(k, P.front()); auto tb = tan(k, P.back()); if(t1 == tf && t2 == tb) { int x = N; while(x > 0 && tan(k, P[x - 1]) == t2) x--; reverse(P.begin() + x, P.end()); }else { cout << "No" << endl; } } P.push_back(k); for(int x = 0; x < N; x++) { int y = (x + 1) % N; int z = (x + 2) % N; if(ccw(x, y, z) != 1) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }