QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#66188#4886. Best Sunjapan022022TL 1497ms4396kbC++2023.5kb2022-12-07 23:25:062022-12-07 23:25:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-07 23:25:06]
  • 评测
  • 测评结果:TL
  • 用时:1497ms
  • 内存:4396kb
  • [2022-12-07 23:25:06]
  • 提交

answer

#line 1 "library/my_template.hpp"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;

template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define FOR4_R(i, a, b, c) for (ll i = (b)-1; i >= ll(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) \
  overload4(__VA_ARGS__, FOR4_R, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)

#define FOR_subset(t, s) for (ll t = s; t >= 0; t = (t == 0 ? -1 : (t - 1) & s))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll

template <typename T, typename U>
T SUM(const vector<U> &A) {
  T sum = 0;
  for (auto &&a: A) sum += a;
  return sum;
}

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T pick(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}

template <typename T>
T pick(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}

template <typename T>
T pick(pqg<T> &que) {
  assert(que.size());
  T a = que.top();
  que.pop();
  return a;
}

template <typename T>
T pick(vc<T> &que) {
  assert(que.size());
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename T, typename U>
T ceil(T x, U y) {
  return (x > 0 ? (x + y - 1) / y : x / y);
}

template <typename T, typename U>
T floor(T x, U y) {
  return (x > 0 ? x / y : (x - y + 1) / y);
}

template <typename T, typename U>
pair<T, T> divmod(T x, U y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template <typename F>
ll binary_search(F check, ll ok, ll ng) {
  assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return ok;
}

template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
  FOR(iter) {
    double x = (ok + ng) / 2;
    tie(ok, ng) = (check(x) ? mp(x, ng) : mp(ok, x));
  }
  return (ok + ng) / 2;
}

template <class T, class S>
inline bool chmax(T &a, const S &b) {
  return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
  return (a > b ? a = b, 1 : 0);
}

vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  FOR(i, S.size()) { A[i] = S[i] - first_char; }
  return A;
}

template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
  int N = A.size();
  vector<T> B(N + 1);
  FOR(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

template <typename CNT, typename T>
vc<CNT> bincount(const vc<T> &A, int size) {
  vc<CNT> C(size);
  for (auto &&x: A) { ++C[x]; }
  return C;
}

// stable
template <typename T>
vector<int> argsort(const vector<T> &A) {
  vector<int> ids(A.size());
  iota(all(ids), 0);
  sort(all(ids),
       [&](int i, int j) { return A[i] < A[j] || (A[i] == A[j] && i < j); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
  int n = len(I);
  vc<T> B(n);
  FOR(i, n) B[i] = A[I[i]];
  return B;
}
#line 1 "library/other/io.hpp"
// based on yosupo's fastio
#include <unistd.h>

namespace fastio {
// クラスが read(), print() を持っているかを判定するメタ関数
struct has_write_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.write(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_write : public decltype(has_write_impl::check<T>(std::declval<T>())) {
};

struct has_read_impl {
  template <class T>
  static auto check(T &&x) -> decltype(x.read(), std::true_type{});

  template <class T>
  static auto check(...) -> std::false_type;
};

template <class T>
class has_read : public decltype(has_read_impl::check<T>(std::declval<T>())) {};

struct Scanner {
  FILE *fp;
  char line[(1 << 15) + 1];
  size_t st = 0, ed = 0;
  void reread() {
    memmove(line, line + st, ed - st);
    ed -= st;
    st = 0;
    ed += fread(line + ed, 1, (1 << 15) - ed, fp);
    line[ed] = '\0';
  }
  bool succ() {
    while (true) {
      if (st == ed) {
        reread();
        if (st == ed) return false;
      }
      while (st != ed && isspace(line[st])) st++;
      if (st != ed) break;
    }
    if (ed - st <= 50) {
      bool sep = false;
      for (size_t i = st; i < ed; i++) {
        if (isspace(line[i])) {
          sep = true;
          break;
        }
      }
      if (!sep) reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_same<T, string>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    while (true) {
      size_t sz = 0;
      while (st + sz < ed && !isspace(line[st + sz])) sz++;
      ref.append(line + st, sz);
      st += sz;
      if (!sz || st != ed) break;
      reread();
    }
    return true;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  bool read_single(T &ref) {
    if (!succ()) return false;
    bool neg = false;
    if (line[st] == '-') {
      neg = true;
      st++;
    }
    ref = T(0);
    while (isdigit(line[st])) { ref = 10 * ref + (line[st++] & 0xf); }
    if (neg) ref = -ref;
    return true;
  }
  template <typename T,
            typename enable_if<has_read<T>::value>::type * = nullptr>
  inline bool read_single(T &x) {
    x.read();
    return true;
  }
  bool read_single(double &ref) {
    string s;
    if (!read_single(s)) return false;
    ref = std::stod(s);
    return true;
  }
  bool read_single(char &ref) {
    string s;
    if (!read_single(s) || s.size() != 1) return false;
    ref = s[0];
    return true;
  }
  template <class T>
  bool read_single(vector<T> &ref) {
    for (auto &d: ref) {
      if (!read_single(d)) return false;
    }
    return true;
  }
  template <class T, class U>
  bool read_single(pair<T, U> &p) {
    return (read_single(p.first) && read_single(p.second));
  }
  template <size_t N = 0, typename T>
  void read_single_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
      auto &x = std::get<N>(t);
      read_single(x);
      read_single_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool read_single(tuple<T...> &tpl) {
    read_single_tuple(tpl);
    return true;
  }
  void read() {}
  template <class H, class... T>
  void read(H &h, T &... t) {
    bool f = read_single(h);
    assert(f);
    read(t...);
  }
  Scanner(FILE *fp) : fp(fp) {}
};

struct Printer {
  Printer(FILE *_fp) : fp(_fp) {}
  ~Printer() { flush(); }

  static constexpr size_t SIZE = 1 << 15;
  FILE *fp;
  char line[SIZE], small[50];
  size_t pos = 0;
  void flush() {
    fwrite(line, 1, pos, fp);
    pos = 0;
  }
  void write(const char val) {
    if (pos == SIZE) flush();
    line[pos++] = val;
  }
  template <class T, enable_if_t<is_integral<T>::value, int> = 0>
  void write(T val) {
    if (pos > (1 << 15) - 50) flush();
    if (val == 0) {
      write('0');
      return;
    }
    if (val < 0) {
      write('-');
      val = -val; // todo min
    }
    size_t len = 0;
    while (val) {
      small[len++] = char(0x30 | (val % 10));
      val /= 10;
    }
    for (size_t i = 0; i < len; i++) { line[pos + i] = small[len - 1 - i]; }
    pos += len;
  }
  void write(const string s) {
    for (char c: s) write(c);
  }
  void write(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++) write(s[i]);
  }
  void write(const double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  void write(const long double x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << x;
    string s = oss.str();
    write(s);
  }
  template <typename T,
            typename enable_if<has_write<T>::value>::type * = nullptr>
  inline void write(T x) {
    x.write();
  }
  template <class T>
  void write(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  template <class T, class U>
  void write(const pair<T, U> val) {
    write(val.first);
    write(' ');
    write(val.second);
  }
  template <size_t N = 0, typename T>
  void write_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
      if constexpr (N > 0) { write(' '); }
      const auto x = std::get<N>(t);
      write(x);
      write_tuple<N + 1>(t);
    }
  }
  template <class... T>
  bool write(tuple<T...> tpl) {
    write_tuple(tpl);
    return true;
  }
  template <class T, size_t S>
  void write(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
      if (i) write(' ');
      write(val[i]);
    }
  }
  void write(i128 val) {
    string s;
    bool negative = 0;
    if (val < 0) {
      negative = 1;
      val = -val;
    }
    while (val) {
      s += '0' + int(val % 10);
      val /= 10;
    }
    if (negative) s += "-";
    reverse(all(s));
    if (len(s) == 0) s = "0";
    write(s);
  }
};
Scanner scanner = Scanner(stdin);
Printer printer = Printer(stdout);
void flush() { printer.flush(); }
void print() { printer.write('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  printer.write(head);
  if (sizeof...(Tail)) printer.write(' ');
  print(forward<Tail>(tail)...);
}

void read() {}
template <class Head, class... Tail>
void read(Head &head, Tail &... tail) {
  scanner.read(head);
  read(tail...);
}
} // namespace fastio
using fastio::print;
using fastio::flush;
using fastio::read;

#define INT(...)   \
  int __VA_ARGS__; \
  read(__VA_ARGS__)
#define LL(...)   \
  ll __VA_ARGS__; \
  read(__VA_ARGS__)
#define STR(...)      \
  string __VA_ARGS__; \
  read(__VA_ARGS__)
#define CHAR(...)   \
  char __VA_ARGS__; \
  read(__VA_ARGS__)
#define DBL(...)      \
  double __VA_ARGS__; \
  read(__VA_ARGS__)

#define VEC(type, name, size) \
  vector<type> name(size);    \
  read(name)
#define VV(type, name, h, w)                     \
  vector<vector<type>> name(h, vector<type>(w)); \
  read(name)

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 1 "library/geo/count_points_in_triangles.hpp"

#line 2 "library/geo/angle_sort.hpp"

#line 2 "library/geo/base.hpp"
template <typename T>
struct Point {
  T x, y;

  Point() = default;

  template <typename A, typename B>
  Point(A x, B y) : x(x), y(y) {}

  template <typename A, typename B>
  Point(pair<A, B> p) : x(p.fi), y(p.se) {}

  Point operator+(Point p) const { return {x + p.x, y + p.y}; }
  Point operator-(Point p) const { return {x - p.x, y - p.y}; }
  bool operator==(Point p) const { return x == p.x && y == p.y; }
  Point operator-() const { return {-x, -y}; }

  bool operator<(Point p) const {
    if (x != p.x) return x < p.x;
    return y < p.y;
  }
  T dot(Point other) { return x * other.x + y * other.y; }
  T det(Point other) { return x * other.y - y * other.x; }

  void read() { fastio::read(x), fastio::read(y); }
  void write() { fastio::printer.write(pair<T, T>({x, y})); }
};

template <typename REAL, typename T>
REAL dist(Point<T> A, Point<T> B) {
  A = A - B;
  T p = A.dot(A);
  return sqrt(REAL(p));
}

template <typename T>
struct Line {
  T a, b, c;

  Line(T a, T b, T c) : a(a), b(b), c(c) {}
  Line(Point<T> A, Point<T> B) {
    a = A.y - B.y;
    b = B.x - A.x;
    c = A.x * B.y - A.y * B.x;
  }
  Line(T x1, T y1, T x2, T y2) : Line(Point<T>(x1, y1), Point<T>(x2, y2)) {}

  template <typename U>
  U eval(Point<U> P) {
    return a * P.x + b * P.y + c;
  }

  template <typename U>
  T eval(U x, U y) {
    return a * x + b * y + c;
  }

  bool is_parallel(Line other) { return a * other.b - b * other.a == 0; }

  bool is_orthogonal(Line other) { return a * other.a + b * other.b == 0; }
};

template <typename T>
struct Segment {
  Point<T> A, B;

  Segment(Point<T> A, Point<T> B) : A(A), B(B) {}
  Segment(T x1, T y1, T x2, T y2)
      : Segment(Point<T>(x1, y1), Point<T>(x2, y2)) {}

  Line<T> to_Line() { return Line(A, B); }
};

template <typename T>
struct Circle {
  Point<T> O;
  T r;
  Circle(Point<T> O, T r) : O(O), r(r) {}
  Circle(T x, T y, T r) : O(Point<T>(x, y)), r(r) {}
};

template <typename T>
struct Polygon {
  vc<Point<T>> points;
  T a;

  template <typename A, typename B>
  Polygon(vc<pair<A, B>> pairs) {
    for (auto&& [a, b]: pairs) points.eb(Point<T>(a, b));
    build();
  }
  Polygon(vc<Point<T>> points) : points(points) { build(); }

  int size() { return len(points); }

  template <typename REAL>
  REAL area() {
    return a * 0.5;
  }

  template <enable_if_t<is_integral<T>::value, int> = 0>
  T area_2() {
    return a;
  }

  bool is_convex() {
    FOR(j, len(points)) {
      int i = (j == 0 ? len(points) - 1 : j - 1);
      int k = (j == len(points) - 1 ? 0 : j + 1);
      if ((points[j] - points[i]).det(points[k] - points[j]) < 0) return false;
    }
    return true;
  }

private:
  void build() {
    a = 0;
    FOR(i, len(points)) {
      int j = (i + 1 == len(points) ? 0 : i + 1);
      a += points[i].det(points[j]);
    }
    if (a < 0) {
      a = -a;
      reverse(all(points));
    }
  }
};
#line 4 "library/geo/angle_sort.hpp"

// 偏角ソートに対する argsort
template <typename T>
vector<int> angle_argsort(vector<Point<T>>& P) {
  vector<int> lower, origin, upper;
  const Point<T> O = {0, 0};
  FOR(i, len(P)) {
    if (P[i] == O) origin.eb(i);
    elif ((P[i].y < 0) || (P[i].y == 0 && P[i].x > 0)) lower.eb(i);
    else upper.eb(i);
  }
  sort(all(lower), [&](auto& i, auto& j) { return P[i].det(P[j]) > 0; });
  sort(all(upper), [&](auto& i, auto& j) { return P[i].det(P[j]) > 0; });
  auto& I = lower;
  I.insert(I.end(), all(origin));
  I.insert(I.end(), all(upper));
  return I;
}

// 偏角ソートに対する argsort
template <typename T>
vector<int> angle_argsort(vector<pair<T, T>>& P) {
  vc<Point<T>> tmp(len(P));
  FOR(i, len(P)) tmp[i] = Point<T>(P[i]);
  return angle_argsort<T>(tmp);
}

// inplace に偏角ソートする
// index が欲しい場合は angle_argsort
template <typename T>
void angle_sort(vector<Point<T>>& P) {
  auto I = angle_argsort<T>(P);
  P = rearrange(P, I);
}

// inplace に偏角ソートする
// index が欲しい場合は angle_argsort
template <typename T>
void angle_sort(vector<pair<T, T>>& P) {
  auto I = angle_argsort<T>(P);
  P = rearrange(P, I);
}
#line 2 "library/random/base.hpp"

u64 RNG_64() {
  static uint64_t x_
      = uint64_t(chrono::duration_cast<chrono::nanoseconds>(
                     chrono::high_resolution_clock::now().time_since_epoch())
                     .count())
        * 10150724397891781847ULL;
  x_ ^= x_ << 7;
  return x_ ^= x_ >> 9;
}

u64 RNG(u64 lim) { return RNG_64() % lim; }

ll RNG(ll l, ll r) { return l + RNG_64() % (r - l); }
#line 5 "library/geo/count_points_in_triangles.hpp"

// 点群 A, B を入力 (Point<ll>)
// query(i,j,k):三角形 AiAjAk 内部の Bl の個数(非負)を返す
// 前計算 O(N^2M)、クエリ O(1)
struct Count_Points_In_Triangles {
  using P = Point<ll>;
  const int LIM = 1'000'000'000 + 10;
  vc<P> A, B;
  vc<int> I, rk; // O から見た偏角ソート順を管理
  vc<int> point; // A[i] と一致する B[j] の数え上げ
  vvc<int> seg;  // 線分 A[i]A[j] 内にある B[k] の数え上げ
  vvc<int> tri;  // OA[i]A[j] 内部にある B[k] の数え上げ
  Count_Points_In_Triangles(vc<P> A, vc<P> B) : A(A), B(B) {
    for (auto&& p: A) assert(-LIM < min(p.x, p.y) && max(p.x, p.y) < LIM);
    for (auto&& p: B) assert(-LIM < min(p.x, p.y) && max(p.x, p.y) < LIM);
    build();
  }

  int query(int i, int j, int k) {
    i = rk[i], j = rk[j], k = rk[k];
    if (i > j) swap(i, j);
    if (j > k) swap(j, k);
    if (i > j) swap(i, j);
    assert(i <= j && j <= k);

    ll d = (A[j] - A[i]).det(A[k] - A[i]);
    if (d == 0) return 0;
    if (d > 0) { return tri[i][j] + tri[j][k] - tri[i][k] - seg[i][k]; }
    int x = tri[i][k] - tri[i][j] - tri[j][k];
    return x - seg[i][j] - seg[j][k] - point[j];
  }

private:
  P take_origin() {
    int N = len(A), M = len(B);
    while (1) {
      P O = P{-LIM, RNG(-LIM, LIM)};
      bool ok = 1;
      FOR(i, N) FOR(j, N) {
        if (A[i] == A[j]) continue;
        if ((A[i] - O).det(A[j] - O) == 0) ok = 0;
      }
      FOR(i, N) FOR(j, M) {
        if (A[i] == B[j]) continue;
        if ((A[i] - O).det(B[j] - O) == 0) ok = 0;
      }
      if (ok) return O;
    }
    return P{};
  }

  void build() {
    P O = take_origin();
    for (auto&& p: A) p = p - O;
    for (auto&& p: B) p = p - O;
    int N = len(A), M = len(B);
    I.resize(N), rk.resize(N);
    iota(all(I), 0);
    sort(all(I), [&](auto& a, auto& b) -> bool { return A[a].det(A[b]) > 0; });
    FOR(i, N) rk[I[i]] = i;
    A = rearrange(A, I);
    point.assign(N, 0);
    seg.assign(N, vc<int>(N));
    tri.assign(N, vc<int>(N));

    FOR(i, N) FOR(j, M) if (A[i] == B[j])++ point[i];
    FOR(i, N) FOR(j, i + 1, N) {
      FOR(k, M) {
        if (A[i].det(B[k]) <= 0) continue;
        if (A[j].det(B[k]) >= 0) continue;
        ll d = (B[k] - A[i]).det(A[j] - A[i]);
        if (d == 0) ++seg[i][j];
        if (d < 0) ++tri[i][j];
      }
    }
  }
};
#line 5 "main.cpp"

using Re = double;
using P = Point<ll>;

void solve() {
  INT(N);
  VEC(P, A, N);
  Count_Points_In_Triangles CT(A, A);

  // 線分 i->j を傾き順でソートする
  vc<pair<int, int>> IJ;
  {
    vc<P> tmp;
    FOR(i, N) FOR(j, N) tmp.eb(A[j] - A[i]);
    auto I = angle_argsort(tmp);
    for (auto&& k: I) {
      auto [i, j] = divmod(k, N);
      if (i != j) IJ.eb(i, j);
    }
  }

  // i->j のときに足すべき面積
  vv(Re, AREA, N, N);
  FOR(i, N) FOR(j, N) AREA[i][j] = A[i].det(A[j]) * 0.5;

  auto angle = [&](P p) -> Re {
    int g = gcd(p.x, p.y);
    if (g == 0) g = 1;
    return atan2(p.y / g, p.x / g);
  };

  // i->j のときに足すべき長さ。初手 / 途中 / 最後。
  vvv(Re, LEN, 3, N, N);
  FOR(i, N) FOR(j, N) {
    // 自分自身
    Re d = dist<Re>(A[i], A[j]);
    LEN[0][i][j] += d;
    LEN[1][i][j] += d;
    LEN[2][i][j] += d;
  }
  // i->j のときに足すべき長さ、まず帯状領域のものについて
  // 「ちょうど 90 度」はここに含めておく
  FOR(i, N) FOR(j, N) if (i != j) {
    FOR(k, N) {
      if (k == i || k == j) continue;
      if ((A[j] - A[i]).dot(A[k] - A[i]) < 0) continue;
      if ((A[i] - A[j]).dot(A[k] - A[j]) < 0) continue;
      if ((A[k] - A[i]).det(A[j] - A[i]) <= 0) continue;
      Re d = min(dist<Re>(A[i], A[k]), dist<Re>(A[j], A[k]));
      LEN[0][i][j] += d;
      LEN[1][i][j] += d;
      LEN[2][i][j] += d;
    }
    FOR(k, N) {
      // if (k == i || k == j) continue;
      // -180 < ik + 90 < ij のときに、LEN0 に +
      // -180 < jk + 90 <= ij のときに、LEN1 に -
      // ik + 90 <= ij のときに、LEN1 に +
      // ij < jk+90 <= 180 のときに、LEN2 に +
      Re IJ = angle(A[j] - A[i]);
      Re IK = angle({-(A[k].y - A[i].y), +(A[k].x - A[i].x)});
      Re JK = angle({-(A[k].y - A[j].y), +(A[k].x - A[j].x)});
      Re di = dist<Re>(A[i], A[k]);
      Re dj = dist<Re>(A[j], A[k]);
      if (IK < IJ) LEN[0][i][j] += di;
      if (JK <= IJ) LEN[0][i][j] -= dj, LEN[1][i][j] -= dj;
      if (IK < IJ) LEN[1][i][j] += di, LEN[2][i][j] += di;
      if (IJ < JK) LEN[2][i][j] += dj;
    }
  }

  Re ANS = 0;
  Re eps = 1e-9;

  auto check = [&](const int s, Re w) -> bool {
    // s からはじめて、S - wP > 0 を達成できるか?
    const ll INF = 1LL << 60;
    vc<Re> dp(N, -INF);
    dp[s] = 0.0;
    for (auto&& [i, j]: IJ) {
      if (dp[i] == -INF) continue;
      if (CT.query(s, i, j) > 0) continue;
      if (i == s) { chmax(dp[j], dp[i] + AREA[i][j] - w * LEN[0][i][j]); }
      elif (j == s) { chmax(dp[j], dp[i] + AREA[i][j] - w * LEN[2][i][j]); }
      elif (i != s && j != s) {
        chmax(dp[j], dp[i] + AREA[i][j] - w * LEN[1][i][j]);
      }
    }
    return dp[s] > eps;
  };

  vc<bool> done(N);
  FOR(N) {
    int s = [&]() {
      while (1) {
        int s = RNG(0, N);
        if (done[s]) continue;
        return s;
      }
      return -1;
    }();
    done[s] = 1;

    if (!check(s, ANS + eps)) continue;
    Re lo = ANS + eps, hi = 4e12;
    FOR(80) {
      Re mi = (lo + hi) / 2;
      bool ok = check(s, mi);
      if (ok) lo = mi;
      if (!ok) hi = mi;
    }
    ANS = lo;
  }
  print(ANS);
}

signed main() {
  INT(T);
  FOR(T) solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4080kb

input:

4
3
-1 -1
1 -1
0 1
4
0 0
10 0
0 10
8 1
5
2 0
-2 0
1 1
-1 1
0 3
8
4 4
-4 4
4 -4
-4 -4
5 6
-6 5
-5 -6
6 -5

output:

0.309016994217240
1.236861427677652
0.271137541410386
1.563100209466980

result:

ok 4 numbers

Test #2:

score: 0
Accepted
time: 150ms
memory: 4144kb

input:

10000
3
702262 828158
-350821 -420883
-466450 13507
3
28647 -193498
126436 -864937
-287798 738936
3
270358 -269567
745815 -485408
834083 677952
3
-2036 -403634
742978 -263774
975937 -609237
3
584248 -472620
482016 -356760
284902 903881
3
-292004 504925
-935756 373793
-781101 -434659
3
-858513 684433...

output:

85789.087398353542085
18268.519361672089872
102489.988390262238681
66685.754428080181242
18674.657937414340267
106468.965131972145173
14427.024651071094922
29966.245302542913123
143547.751083587383619
13097.175688126128080
162410.168316980794771
72070.932417874690145
29369.992627886884293
52867.2944...

result:

ok 10000 numbers

Test #3:

score: 0
Accepted
time: 116ms
memory: 4124kb

input:

10000
3
2 2
2 -2
-5 -5
3
-3 5
5 -4
2 -2
3
-4 1
2 -2
-4 4
3
1 -4
2 1
-4 1
3
2 1
-1 1
-3 3
3
4 5
3 -1
-3 -3
3
1 5
5 0
5 -1
3
2 -3
-5 -3
5 3
3
-4 4
0 -5
5 4
3
2 -3
5 0
2 -5
3
-2 -3
5 -3
5 4
3
-1 4
4 4
4 3
3
5 3
-1 4
2 -1
3
2 -3
4 3
-4 3
3
0 4
-2 -2
-1 -3
3
-2 0
-4 -2
4 2
3
-3 -1
3 1
1 -3
3
2 -5
2 3
-4 ...

output:

0.650700701070052
0.226809070244137
0.494682566160728
0.825532631204007
0.267532474626131
0.737928456332666
0.136852946647847
0.827745795519459
1.389628120365936
0.248476166361209
1.025126265805109
0.225245121511036
0.798168850416742
1.052177633726446
0.270090756669430
0.221028003503229
0.6549291473...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 194ms
memory: 4140kb

input:

5625
4
-405394 -381883
602267 -335687
-620806 984110
271283 531233
4
196903 -993060
290851 358123
-890076 -717709
-681138 209884
4
-849589 607722
-21517 -586295
208561 -220953
924518 622983
4
-832186 456270
289934 43656
636006 339718
188963 113907
4
-305762 -872205
-520125 368722
-774548 984204
4245...

output:

232625.004274430393707
268175.826985963911284
159589.323630517290439
60440.753042598487809
133893.123436351859709
63201.990748626820277
167697.663406134757679
129470.013284316300997
126903.854072810136131
106643.971263097046176
131692.311227904719999
100421.055016212529154
148490.274817902391078
688...

result:

ok 5625 numbers

Test #5:

score: 0
Accepted
time: 156ms
memory: 4132kb

input:

5625
4
-2 -1
4 -5
-2 -4
-4 -4
4
-1 -5
4 4
2 -5
-5 1
4
-3 -4
-3 -1
-5 -1
4 -2
4
-2 4
-4 1
-1 -1
5 -4
4
-3 -5
-1 4
5 -1
3 5
4
-4 -2
1 4
-1 1
3 4
4
-5 3
-3 3
5 -4
-1 4
4
1 2
2 -5
1 0
0 -3
4
-5 -4
2 -3
5 3
-3 2
4
2 -2
-4 3
1 -4
-5 -5
4
-3 5
-2 4
1 3
1 -4
4
0 -5
5 -5
0 -2
-3 2
4
0 5
-1 -4
-2 0
4 -1
4
4 -...

output:

0.491968206772617
1.608023936284702
0.676463563481186
0.814682126414407
1.572795403267834
0.202044801584030
0.442367305765967
0.305583212279053
1.508906909893292
1.322787523737014
0.521855949158265
0.398280450232526
1.219494625779189
1.177491255268827
1.395102692973639
1.073773125969571
0.7540897904...

result:

ok 5625 numbers

Test #6:

score: 0
Accepted
time: 227ms
memory: 4152kb

input:

3600
5
114127 146710
467065 -311758
189643 449065
-303893 -215009
-789281 -140748
5
-449893 654165
-899120 -560520
719351 652759
285007 471281
987628 -767128
5
-587522 89736
-355416 -178001
801765 512722
314119 -136906
350051 762194
5
85697 920768
161507 -533920
-536515 401333
-27632 -987465
112237 ...

output:

84655.199548642136506
270848.726867046905681
202824.036734045512276
135615.191873947740532
119666.508543506162823
89811.870770703477319
254983.153575301344972
189662.747266510996269
64951.657089439431729
154748.442291013780050
214519.682079036196228
163467.532800249318825
278857.257440859044436
1914...

result:

ok 3600 numbers

Test #7:

score: 0
Accepted
time: 181ms
memory: 4128kb

input:

3600
5
2 6
-6 4
4 0
-5 0
3 1
5
0 3
5 -5
2 6
4 0
2 -4
5
2 -2
-6 -3
-5 -5
-1 3
-4 0
5
0 6
-3 -5
5 1
4 -3
-5 6
5
0 -6
-6 -5
-2 6
1 6
2 0
5
2 1
6 5
4 -1
-3 -2
-6 4
5
-1 -2
5 -6
-1 4
-2 3
6 4
5
-6 3
6 -5
4 -4
3 -1
2 -6
5
5 -4
1 -5
1 0
5 -1
3 2
5
-4 6
2 -4
1 -4
5 5
-1 6
5
-3 0
0 6
-2 5
-5 5
2 6
5
2 -1
-4 ...

output:

1.391733814355341
1.060007676049368
1.338660497136608
2.178641491270747
1.867763529512022
1.255064420023239
1.819705452321456
0.946302319143526
1.131643310431369
1.577239085893961
0.521212423100282
1.537179568005399
0.947338474590416
1.047090988085763
0.557229792969016
1.208597020252809
1.2302893723...

result:

ok 3600 numbers

Test #8:

score: 0
Accepted
time: 180ms
memory: 4132kb

input:

3600
5
-3 1
0 -1
2 -3
4 1
5 0
5
-3 -5
1 -5
-2 -2
3 2
1 5
5
-4 -2
4 5
5 3
2 -4
-4 0
5
0 4
-5 3
1 4
-1 1
4 1
5
5 -3
2 -5
-3 -4
-1 1
5 1
5
-5 5
-2 1
-3 2
2 2
-4 5
5
-2 -3
-1 3
1 1
3 -2
-2 -2
5
2 1
-2 -3
-3 -3
5 0
-5 4
5
2 2
-2 5
5 -1
4 -5
-2 4
5
-4 5
-1 -3
-2 5
5 -1
-4 3
5
-5 -4
-1 -3
0 -1
-5 1
-4 -3
5...

output:

0.543380852415936
1.207931264291513
1.575494574190601
0.807518149133358
1.556679601120247
0.682449066971565
0.907440119365144
0.950838997648517
0.853770882844453
1.371308224848877
0.742640802178514
0.401491624020872
0.747427628601607
0.493469159680953
0.711214495049007
0.609299855727899
1.2344361706...

result:

ok 3600 numbers

Test #9:

score: 0
Accepted
time: 183ms
memory: 4140kb

input:

3600
5
0 2
3 -7
7 3
-6 -1
6 -6
5
-3 6
-5 6
-10 -2
-4 -8
-9 8
5
-2 2
2 -9
6 -3
2 10
-5 7
5
-7 9
9 -4
-8 -2
4 10
9 -8
5
-8 -5
-10 0
-7 0
0 -7
6 8
5
10 -7
8 -8
3 1
0 -4
-7 -4
5
2 -9
-3 1
-4 -2
-3 -3
0 1
5
-8 5
-10 6
2 -8
6 -5
-6 8
5
5 8
-8 -9
3 -7
-9 0
-4 3
5
2 -5
2 0
6 7
10 5
-8 -6
5
-10 -2
7 -6
-10 5...

output:

2.105200917171916
1.536768657804009
1.607020250169050
3.526347323447751
1.978433495947134
1.082518584744045
0.946163226621754
1.602327122581572
2.883772155059313
0.940814876098426
1.701362563351895
1.600920246237998
1.933487252551775
0.691865963757284
1.833984299430693
0.630647968964679
3.4339518738...

result:

ok 3600 numbers

Test #10:

score: 0
Accepted
time: 296ms
memory: 4136kb

input:

900
10
-10 -1
8 -6
7 -1
-5 8
-7 -9
4 -2
-9 10
-10 -8
9 9
-3 -6
10
-5 9
-7 -1
-9 -7
-4 6
-5 2
1 -4
10 8
-9 -9
2 0
7 7
10
-3 -7
9 -4
-5 2
1 1
6 7
-4 7
4 -6
0 1
-8 -5
3 -5
10
-3 -10
-8 -7
-5 -5
-6 3
-3 -1
7 -9
1 -5
9 -7
-2 3
-4 9
10
0 1
-3 8
-3 7
4 -10
10 -6
-5 -8
10 4
4 3
0 -8
3 -10
10
4 -5
2 0
-5 -10...

output:

2.606027487289903
1.263341789415628
1.183899114986993
0.882728471598947
1.878227296469852
1.569813583594919
1.553295323552855
1.632832331019136
1.573799484591302
0.997095963137439
0.942482997230413
1.417282633761506
1.401766575032649
1.693986663664259
2.862877851454087
2.055359776998968
2.2087768678...

result:

ok 900 numbers

Test #11:

score: 0
Accepted
time: 385ms
memory: 4072kb

input:

900
10
670067 394291
-797310 -637136
-435933 -923795
120936 309795
-934569 -688829
950758 634654
983083 900196
174829 181896
-191047 177910
258020 672165
10
424046 -657491
391198 -14995
-302986 -597011
-96387 -486090
-164032 -356501
-891789 12548
-703186 -924511
808215 -212606
659523 490088
738901 5...

output:

81290.161838387415628
91483.733196163346292
100154.027055844286224
192606.414820315665565
177441.647434418933699
76150.892372178423102
177358.705373884906294
230115.879266813135473
280209.262845028191805
61218.543021288038290
137504.791637735906988
168344.544041083048796
162167.181814908981323
13310...

result:

ok 900 numbers

Test #12:

score: 0
Accepted
time: 503ms
memory: 4128kb

input:

225
20
-4 -9
-5 3
7 -10
10 7
2 7
1 4
2 2
-5 -1
-9 -1
-3 10
-8 -6
0 -5
7 -4
-6 -8
-7 -5
-1 -7
-1 -3
8 -6
6 3
8 2
20
8 2
6 -8
-3 -6
-2 9
5 -2
0 8
8 0
-7 -9
3 1
4 -10
4 7
-6 -1
-8 -7
2 -8
-8 -1
1 -9
2 -10
1 2
-7 8
-10 3
20
5 8
0 -3
9 -9
-10 -4
-10 -2
9 10
-2 8
-6 -10
6 -6
-3 7
5 10
7 7
-5 -6
-2 3
-4 0
...

output:

0.612786987902879
1.113790722844409
0.761536436760829
1.330805908887518
0.754049224578158
1.332837977355119
0.670314797999748
1.035312805518884
0.906817408476045
0.976966662194348
0.750284896345311
0.778031577905511
0.717904921218540
0.571580229491750
0.772106110146106
0.769291031965376
1.8904459998...

result:

ok 225 numbers

Test #13:

score: 0
Accepted
time: 694ms
memory: 4184kb

input:

225
20
983700 -466859
-20884 -364855
807044 -308568
-785298 910840
-61173 -276993
-872226 -878552
-235162 831941
978289 938037
585612 -598517
545857 403231
-450887 -558997
-293044 -675226
-900628 102932
-836719 -530135
-534412 -681687
-487340 -227869
161252 -557533
397943 464720
170537 68556
413322 ...

output:

103902.052600549708586
185063.038457368209492
60443.657372329791542
118360.364609652649960
157018.785130765987560
103511.465806248685112
65549.699479301794781
67043.358828878874192
105010.270532679773169
93450.057668448440381
96005.228207606458454
54350.098601304707699
134718.535343140305486
98397.3...

result:

ok 225 numbers

Test #14:

score: 0
Accepted
time: 268ms
memory: 4240kb

input:

6
50
-107573 -479674
-523931 117259
705403 519626
-802569 -162243
510741 876735
206326 -333274
448335 -276206
482965 -837837
873180 -965235
-359525 608790
-53827 782310
689038 -718590
739597 111296
420387 -953079
-492679 -243600
-929509 1174
800731 -968797
208236 193620
249265 499134
848153 771472
5...

output:

20480.382854002993554
21190.022149754473503
27821.672595881223970
28113.319340533114882
27223.967607933398540
31857.835710023828142

result:

ok 6 numbers

Test #15:

score: 0
Accepted
time: 1497ms
memory: 4272kb

input:

36
50
569818 -279771
972561 928848
383 744221
-453534 -154445
293032 502859
744851 436690
293077 503053
657 744258
317135 -276665
293067 502799
277103 -439313
282010 -387735
276848 -439025
972274 928763
-110443 -507380
744799 436605
282061 -387926
-453689 -154326
317468 -276534
-453630 -154510
28193...

output:

81019.427454406148172
77527.258772980290814
55029.246423312404659
42253.154385652291239
72715.857822992780712
197374.630740651191445
37469.722581922957033
66130.352995365421521
54454.597806512429088
125611.088368524026009
71800.206273050702293
87529.336768807683256
143932.887614790350199
95010.13468...

result:

ok 36 numbers

Test #16:

score: 0
Accepted
time: 1420ms
memory: 4276kb

input:

36
50
-767165 583573
-284890 -681002
-423448 -259226
-285077 -680913
-921552 -557651
-767105 583853
-423314 -259380
790075 -225214
-921537 -557431
-767305 583770
-767124 583508
-921629 -557448
-423530 -259463
-284954 -680837
-423426 -259294
-423469 -259099
-767302 583744
-921772 -557672
-423503 -259...

output:

36643.605480613958207
73491.058057638088940
355454.440213159949053
76283.491515342233470
114070.220777055394137
102751.942339931905735
346834.508596234139986
142611.057937860634411
246800.067113918281393
131055.886666590740788
22279.887989220529562
215589.657625078805722
83424.868814161847695
51800....

result:

ok 36 numbers

Test #17:

score: 0
Accepted
time: 1418ms
memory: 4396kb

input:

36
50
-757926 470127
-757550 470454
250422 -395772
250548 -395869
568164 -704082
250417 -396082
-757845 470427
444672 170989
250387 -395875
250484 -395866
568177 -704202
-757558 470484
250530 -395763
250488 -395883
-757754 470201
250529 -396062
-757760 470255
568050 -704413
444991 171218
444963 1710...

output:

41461.415731251188845
61470.345902095708880
198910.999967383337207
35019.368645437338273
139342.579707833589055
26339.662839055705263
247086.679248967819149
108103.832978620717768
269038.970057263562921
40491.226764097722480
99838.873958293886972
174035.149737151456065
172811.211970721051330
155604....

result:

ok 36 numbers

Test #18:

score: -100
Time Limit Exceeded

input:

9
100
-79487 826724
571284 354748
-312616 727781
-838024 249391
-79475 826592
796988 -514208
-847898 -839919
584481 896431
-847899 -839656
-312680 727782
22798 138363
466409 -215121
-36729 -925283
677267 -733543
-789119 581936
-789111 581860
271104 629366
571356 354824
-946155 -832752
571238 354954
...

output:


result: