結果

問題 No.3154 convex polygon judge
ユーザー ripity
提出日時 2025-05-20 22:41:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,545 bytes
コンパイル時間 6,234 ms
コンパイル使用メモリ 333,780 KB
実行使用メモリ 20,072 KB
最終ジャッジ日時 2025-05-20 22:41:51
合計ジャッジ時間 11,237 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 13 RE * 1 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#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)]++;
  }
  for(auto [_, c] : cnt_tan) {
    if(c >= 2) {
      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) {
    return ccw(i, k, j);
  });
  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;
}
0