結果

問題 No.3042 拡大コピー
ユーザー Kude
提出日時 2025-02-28 22:25:49
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 5,327 bytes
コンパイル時間 3,378 ms
コンパイル使用メモリ 309,656 KB
実行使用メモリ 8,236 KB
最終ジャッジ日時 2025-03-01 07:39:19
合計ジャッジ時間 5,447 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = double;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

struct Vec {
  using etype = double;  // type of elements
  using ptype = double;  // type of product results
  etype x = 0, y = 0;
  constexpr Vec operator-() const { return {-x, -y}; }
  friend constexpr Vec operator+(const Vec& a, const Vec& b) { return {a.x + b.x, a.y + b.y}; }
  friend constexpr Vec operator-(const Vec& a, const Vec& b) { return {a.x - b.x, a.y - b.y}; }
  friend constexpr ptype operator*(const Vec& a, const Vec& b) { return (ptype)a.x * b.y - (ptype)a.y * b.x; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator*(T c, const Vec& a) { return {c * a.x, c * a.y}; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator*(const Vec& a, T c) { return c * a; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  friend constexpr Vec operator/(const Vec& a, T c) { return {a.x / c, a.y / c}; }
  Vec& operator+=(const Vec& a) { x += a.x; y += a.y; return *this; }
  Vec& operator-=(const Vec& a) { x -= a.x; y -= a.y; return *this; }
  template <class T, enable_if_t<is_integral_v<T>>* = nullptr>
  Vec& operator*=(T c) { x *= c; y *= c; return *this; }
  friend constexpr bool operator==(const Vec& a, const Vec& b) { return a.x == b.x && a.y == b.y; }
  friend constexpr bool operator!=(const Vec& a, const Vec& b) { return !(a == b); }
  constexpr int quadrant() const { return y > 0 ? (x > 0 ? 0 : 1) : y < 0 ? (x < 0 ? 2 : 3) : (x > 0 ? 0 : x < 0 ? 2 : -1); }
  friend constexpr bool operator<(const Vec& a, const Vec& b) {
    int qa = a.quadrant(), qb = b.quadrant();
    if (qa != qb) return qa < qb;
    ptype p1 = (ptype)a.x * b.y, p2 = (ptype)a.y * b.x;
    return p1 > p2 || (p1 == p2 && (a.x != 0 ? abs(a.x) < abs(b.x) : abs(a.y) < abs(b.y)));
  }
  friend constexpr bool operator>(const Vec& a, const Vec& b) { return b < a; }
  friend constexpr bool operator<=(const Vec& a, const Vec& b) { return !(b < a); }
  friend constexpr bool operator>=(const Vec& a, const Vec& b) { return !(a < b); }
  constexpr int ccw(const Vec& u, const Vec& v) const { ptype p = (u - *this) * (v - *this); return p > 0 ? 1 : p < 0 ? -1 : 0; }
  static constexpr bool intersects(const Vec& a, const Vec& b, const Vec& c, const Vec& d) { return a.ccw(b, c) * a.ccw(b, d) <= 0 && c.ccw(d, a) * c.ccw(d, b) <= 0; }
  constexpr bool parallel_to(const Vec& a) const { return (ptype)x * a.y == (ptype)y * a.x; }
  constexpr ptype dot(const Vec& a) const { return (ptype)x * a.x + (ptype)y * a.y; }
  constexpr ptype norm2() const { return (ptype)x * x + (ptype)y * y; }
  constexpr bool is_zero() const { return x == 0 && y == 0; }
  // constexpr Vec normalize() const {
  //   if (x == 0) return Vec{0, (y == 0 ? 0 : 1)};
  //   etype g = gcd(x, y);
  //   return *this / (x > 0 ? g : -g);
  // }
  constexpr Vec rot90() const { return {-y, x}; }
  // exclusive
  constexpr bool in_between(const Vec& a, const Vec& b) const {
    Vec x = a - *this, y = b - *this;
    return x.parallel_to(y) && x.dot(y) < 0;
  }
  friend std::ostream& operator<< (std::ostream& os, const Vec& t) { return os << t.x << ' ' << t.y; }
  friend std::istream& operator>> (std::istream& os, Vec& t) { return os >> t.x >> t.y; }
};


vector<int> convex_hull(const vector<Vec>& ps) {
  const int n = ps.size();
  if (n <= 1) {
    if (n == 0) return {};
    else return {0};
  }
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    return ps[i].y < ps[j].y || (ps[i].y == ps[j].y && ps[i].x < ps[j].x);
  });
  vector<int> st1, st2;
  for(int i: ord) {
    int sz = st1.size();
    while(sz >= 2 && (ps[st1[sz - 1]] - ps[st1[sz - 2]]) * (ps[i] - ps[st1[sz - 1]]) <= 0) {
      st1.pop_back();
      sz--;
    }
    st1.push_back(i);
  }
  for(int i: ord) {
    int sz = st2.size();
    while(sz >= 2 && (ps[st2[sz - 1]] - ps[st2[sz - 2]]) * (ps[i] - ps[st2[sz - 1]]) >= 0) {
      st2.pop_back();
      sz--;
    }
    st2.push_back(i);
  }
  assert(st1.front() == st2.front() && st1.back() == st2.back());
  st1.insert(st1.end(), st2.rbegin() + 1, st2.rend() - 1);
  return st1;
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<Vec> a(n);
  double s1 = 0, s2 = 0;
  rep(_, 2) {
    rep(i, n) cin >> a[i];
    auto ch = convex_hull(a);
    int sz = ch.size();
    if (sz == 2) {
      s1 = (a[ch[1]] - a[ch[0]]).norm2();
    } else {
      assert(sz > 2);
      rep(i, sz) s1 += a[ch[i]] * a[ch[(i+1)%sz]];
    }
    swap(s1, s2);
  }
  cout << fixed << setprecision(12) << sqrt(double(s2) / s1) << '\n';
}
0