結果
問題 | No.96 圏外です。 |
ユーザー | raven7959 |
提出日時 | 2022-08-30 22:03:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 26,244 bytes |
コンパイル時間 | 4,215 ms |
コンパイル使用メモリ | 262,404 KB |
実行使用メモリ | 22,636 KB |
最終ジャッジ日時 | 2024-11-07 15:50:54 |
合計ジャッジ時間 | 28,224 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 24 ms
5,248 KB |
testcase_05 | AC | 46 ms
5,248 KB |
testcase_06 | AC | 76 ms
5,248 KB |
testcase_07 | AC | 128 ms
5,248 KB |
testcase_08 | AC | 181 ms
5,316 KB |
testcase_09 | AC | 264 ms
6,160 KB |
testcase_10 | AC | 379 ms
6,592 KB |
testcase_11 | AC | 490 ms
7,808 KB |
testcase_12 | AC | 607 ms
9,088 KB |
testcase_13 | AC | 874 ms
9,984 KB |
testcase_14 | AC | 1,057 ms
12,032 KB |
testcase_15 | AC | 1,392 ms
12,928 KB |
testcase_16 | AC | 1,628 ms
15,744 KB |
testcase_17 | AC | 1,863 ms
18,944 KB |
testcase_18 | AC | 2,200 ms
18,432 KB |
testcase_19 | AC | 2,082 ms
18,560 KB |
testcase_20 | AC | 1,639 ms
17,944 KB |
testcase_21 | AC | 1,216 ms
19,528 KB |
testcase_22 | TLE | - |
testcase_23 | AC | 3,789 ms
22,636 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 1,374 ms
14,336 KB |
testcase_26 | AC | 1,879 ms
17,536 KB |
testcase_27 | AC | 1,575 ms
15,616 KB |
ソースコード
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2") #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) (x).begin(), (x).end() #define sz(x) int(x.size()) #define yn(joken) cout<<((joken) ? "Yes" : "No")<<"\n" #define YN(joken) cout<<((joken) ? "YES" : "NO")<<"\n" using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vd = vector<double>; using vld = vector<long double>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvs = vector<vector<string>>; using vvc = vector<vector<char>>; using vvd = vector<vector<double>>; using vvld = vector<vector<long double>>; using vvvi = vector<vector<vector<int>>>; using vvvl = vector<vector<vector<ll>>>; using vvvvi = vector<vector<vector<vector<int>>>>; using vvvvl = vector<vector<vector<vector<ll>>>>; using pii = pair<int,int>; using pll = pair<ll,ll>; const int INF = 1e9; const ll LINF = 2e18; template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } bool ispow2(int i) { return i && (i & -i) == i; } bool ispow2(ll i) { return i && (i & -i) == i; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < int(v.size()) - 1) os << ' '; } return os; } static uint32_t RandXor(){ static uint32_t x=123456789; static uint32_t y=362436069; static uint32_t z=521288629; static uint32_t w=88675123; uint32_t t; t=x^(x<<11); x=y; y=z; z=w; return w=(w^(w>>19))^(t^(t>>8)); } static double Rand01(){ return (RandXor()+0.5)*(1.0/UINT_MAX); } // merge(x,y):mergeする,未併合ならtrueが,併合済みならfalseが返ってくる // leader(x):xの根を返す // size(x):xの属する集合のサイズを返す // same(x,y):x,yが同じ集合に属するかどうか // groups():各集合に含まれる要素を返す struct dsu{ public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b){ assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b){ assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a){ assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a){ assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } vector<vector<int>> groups(){ vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++){ leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } vector<vector<int>> result(_n); for (int i = 0; i < _n; i++){ result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++){ result[leader_buf[i]].push_back(i); } result.erase( remove_if(result.begin(), result.end(), [&](const vector<int> &v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent vector<int> parent_or_size; }; #pragma region geometry namespace geometry { using coordinate_t = double; const coordinate_t PI = std::acos(-1); const coordinate_t EPS = 1e-9; int sgn(coordinate_t a) { return (a < -EPS) ? -1 : (a > EPS) ? 1 : 0; }; struct Point { coordinate_t x, y; Point() { } Point(coordinate_t _x, coordinate_t _y) : x(_x), y(_y) { } Point operator+(const Point &rhs) const { Point res(*this); return res += rhs; } Point operator-(const Point &rhs) const { Point res(*this); return res -= rhs; } Point operator*(const coordinate_t &rhs) const { Point res(*this); return res *= rhs; } Point operator/(const coordinate_t &rhs) const { Point res(*this); return res /= rhs; } inline bool operator<(const Point &b) { if (sgn(x - b.x)) return sgn(x - b.x) < 0; return sgn(y - b.y) < 0; } Point operator+=(const Point &rhs) { x += rhs.x, y += rhs.y; return *this; } Point operator-=(const Point &rhs) { x -= rhs.x, y -= rhs.y; return *this; } Point operator*=(const coordinate_t &rhs) { x *= rhs, y *= rhs; return *this; } Point operator/=(const coordinate_t &rhs) { x /= rhs, y /= rhs; return *this; } coordinate_t abs() const { return std::sqrt(x * x + y * y); } coordinate_t arg() const { return std::atan2(y, x); } Point normal() const { return Point(-y, x); } Point unit() const { return *this / abs(); } }; inline bool operator<(const Point &a, const Point &b) { if (sgn(a.x - b.x)) return sgn(a.x - b.x) < 0; return sgn(a.y - b.y) < 0; } inline bool operator==(const Point &a, const Point &b) { return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0; } inline bool operator>(const Point &a, const Point &b) { if (sgn(a.x - b.x)) return sgn(a.x - b.x) > 0; return sgn(a.y - b.y) > 0; } std::istream &operator>>(std::istream &is, Point &p) { coordinate_t x, y; is >> x >> y; p = {x, y}; return is; } std::ostream &operator<<(std::ostream &os, const Point &p) { return os << p.x << ' ' << p.y; } Point rotate(const Point &p, const coordinate_t &theta) { Point ret; ret.x = p.x * cos(theta) - p.y * sin(theta); ret.y = p.x * sin(theta) + p.y * cos(theta); return ret; } coordinate_t dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } coordinate_t det(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; } const int COUNTER_CLOCKWISE = 1; const int CLOCKWISE = -1; const int ONLINE_BACK = -2; const int ONLINE_FRONT = 2; const int ON_SEGMENT = 0; int ccw(Point a, Point b, Point c) { if (sgn(det(b - a, c - a)) > 0) { return COUNTER_CLOCKWISE; // counter clockwise } if (sgn(det(b - a, c - a)) < 0) { return CLOCKWISE; // clockwise } if (sgn(dot(b - a, c - a)) < 0) { return ONLINE_BACK; // c - a - b } if (sgn(dot(a - b, c - b)) < 0) { return ONLINE_FRONT; // a - b - c } return ON_SEGMENT; // a - c - b } struct Segment { Point a, b; Segment() { } Segment(Point _a, Point _b) : a(_a), b(_b) { } }; std::istream &operator>>(std::istream &is, Segment &s) { Point a, b; is >> a >> b; s = {a, b}; return is; }; struct Line { Point a, b; Line() { } Line(Point _a, Point _b) : a(_a), b(_b) { } Line(const Segment &s) : a(s.a), b(s.b) { } Line vertical_bisector() { Point c = (a + b) / 2; Point v = (a - b).normal(); return {c + v, c - v}; } Point projection(const Point &p) const { return a + (b - a) * (dot(b - a, p - a) / ((b - a).abs() * (b - a).abs())); } Point reflection(const Point &p) const { return projection(p) * 2 - p; } }; std::istream &operator>>(std::istream &is, Line &l) { Point a, b; is >> a >> b; l = {a, b}; return is; }; struct Polygon : std::vector<Point> { Polygon(int n = 0) : std::vector<Point>(n) { } coordinate_t area() const { coordinate_t ret = 0; for (int i = 0; i < (int)size(); i++) { ret += det((*this)[i], (*this)[(i + 1) % (int)size()]); } ret /= 2.0; ret = std::fabs(ret); return ret; } bool is_convex() const { for (int i = 0; i < (int)size(); i++) { if (ccw((*this)[i], (*this)[(i + 1) % (int)size()], (*this)[(i + 2) % (int)size()]) == CLOCKWISE) { return false; } } return true; } coordinate_t diameter() const { assert(is_convex()); coordinate_t ret = 0; int r = 0; for (int l = 0; l < (int)size(); l++) { while (sgn(((*this)[l] - (*this)[r]).abs() - ((*this)[l] - (*this)[(r + 1) % (int)size()]).abs()) < 0) { r++; if (r == (int)size()) r = 0; } ret = std::max(ret, ((*this)[l] - (*this)[r]).abs()); } return ret; } int contain(const Point &p) const { bool is_in = false; for (int i = 0; i < (int)size(); i++) { int ccw_ = ccw((*this)[i], (*this)[(i + 1) % (int)size()], p); if (ccw_ == ON_SEGMENT) { return 1; // p is on a segment of polygon } Point a = (*this)[i] - p, b = (*this)[(i + 1) % (int)size()] - p; if (b < a) std::swap(a, b); if (sgn(a.x) <= 0 && sgn(b.x) > 0 && sgn(det(a, b)) < 0) is_in ^= true; } return is_in ? 2 /* polygon contains p */ : 0; } }; struct Circle { Point c; coordinate_t r; Circle() { } Circle(Point _c, coordinate_t _r) : c(_c), r(_r) { assert(sgn(r) >= 0); } coordinate_t area() const { return r * r * PI; } int contain(const Point &p) const { return sgn((c - p).abs() - r) > 0 ? 0 : sgn((c - p).abs() - r) == 0 ? 1 : 2; } }; bool intersect(const Segment &s1, const Segment &s2); bool intersect(const Line &l1, const Line &l2); bool intersect(const Segment &s, const Line &l); bool intersect(const Segment &s, const Circle &c); bool intersect(const Line &s, const Circle &c); Point cross_point(const Segment &s1, const Segment &s2); Point cross_point(const Line &l1, const Line &l2); Point cross_point(const Segment &s, const Line &l); std::vector<Point> cross_points(const Segment &s, const Circle &c); std::vector<Point> cross_points(const Line &l, const Circle &c); coordinate_t dist(const Point &p1, const Point &p2) { return (p1 - p2).abs(); } coordinate_t dist(const Segment &s, const Point &p) { if (sgn(dot(s.b - s.a, p - s.a)) < 0) { return (p - s.a).abs(); } if (sgn(dot(s.a - s.b, p - s.b)) < 0) { return (p - s.b).abs(); } return std::fabs(det(p - s.a, s.b - s.a)) / (s.b - s.a).abs(); } coordinate_t dist(const Point &p, const Segment &s) { return dist(s, p); } coordinate_t dist(const Segment &s1, const Segment &s2) { if (intersect(s1, s2)) return 0; return std::min( {dist(s1, s2.a), dist(s1, s2.b), dist(s2, s1.a), dist(s2, s1.b)}); } coordinate_t dist(const Line &l, const Point &p) { return std::fabs(det(p - l.a, l.b - l.a)) / (l.b - l.a).abs(); } coordinate_t dist(const Point &p, const Line &l) { return dist(l, p); } coordinate_t dist(const Line &l1, const Line &l2) { if (intersect(l1, l2)) return 0; return dist(l1.a, l2); } coordinate_t dist(const Segment &s, const Line &l) { if (intersect(s, l)) return 0; return std::min(dist(s.a, l), dist(s.b, l)); } coordinate_t dist(const Line &l, const Segment &s) { return dist(s, l); } bool intersect(const Segment &s1, const Segment &s2) { return sgn(ccw(s1.a, s1.b, s2.a) * ccw(s1.a, s1.b, s2.b)) <= 0 && sgn(ccw(s2.a, s2.b, s1.a) * ccw(s2.a, s2.b, s1.b)) <= 0; } bool intersect(const Line &l1, const Line &l2) { return sgn(det(l1.b - l1.a, l2.b - l2.a)) != 0; } bool intersect(const Segment &s, const Line &l) { return ccw(l.a, l.b, s.a) * ccw(l.a, l.b, s.b) == -1; } bool intersect(const Line &l, const Segment &s) { return intersect(s, l); } bool intersect(const Segment &s, const Circle &c) { if (sgn(dist(s, c.c) - c.r) > 0) return false; return !(sgn((c.c - s.a).abs() - c.r) < 0 && sgn((c.c - s.b).abs() - c.r) < 0); } bool intersect(const Circle &c, const Segment &s) { return intersect(s, c); } bool intersect(const Line &l, const Circle &c) { return sgn(dist(l, c.c) - c.r) <= 0; } bool intersect(const Circle &c, const Line &l) { return intersect(l, c); } bool intersect(Circle c1, Circle c2) { return sgn((c1.c - c2.c).abs() - (c1.r + c2.r)) <= 0 && sgn((c1.c - c2.c).abs() - std::fabs(c1.r - c2.r)) >= 0; } Point cross_point(const Segment &s1, const Segment &s2) { assert(intersect(s1, s2)); return cross_point(Line(s1), Line(s2)); } Point cross_point(const Segment &s, const Line &l) { assert(intersect(s, l)); return s.a + (s.b - s.a) * (det(l.a - s.a, l.b - l.a) / det(s.b - s.a, l.b - l.a)); } Point cross_point(const Line &l, const Segment &s) { return cross_point(s, l); } Point cross_point(const Line &l1, const Line &l2) { assert(intersect(l1, l2)); return l1.a + (l1.b - l1.a) * (det(l2.a - l1.a, l2.b - l2.a) / det(l1.b - l1.a, l2.b - l2.a)); } std::vector<Point> cross_points(const Segment &s, const Circle &c) { if (!intersect(s, c)) return {}; std::vector<Point> ret = cross_points(Line(s), c); ret.erase(std::remove_if(ret.begin(), ret.end(), [&](Point p) { return !(p == s.a) && !(p == s.b) && (p < s.a) == (p < s.b); }), ret.end()); return ret; } std::vector<Point> cross_points(const Circle &c, const Segment &s) { return cross_points(s, c); } std::vector<Point> cross_points(const Line &l, const Circle &c) { if (!intersect(l, c)) return {}; Point p = l.projection(c.c); Point v = (l.b - l.a) * std::sqrt(c.r * c.r - (p - c.c).abs() * (p - c.c).abs()) / (l.b - l.a).abs(); v = std::max(v, v * -1); return {p - v, p + v}; } std::vector<Point> cross_points(const Circle &c, const Line &l) { return cross_points(l, c); } std::vector<Point> cross_points(Circle c1, Circle c2) { if (!intersect(c1, c2)) return {}; coordinate_t d = (c1.c - c2.c).abs(); coordinate_t d1 = (d + (c1.r * c1.r - c2.r * c2.r) / d) / 2; coordinate_t h = std::sqrt(c1.r * c1.r - d1 * d1); Point v = (c2.c - c1.c).normal(); v *= h / v.abs(); std::vector<Point> ret = {c1.c + (c2.c - c1.c) * (d1 / d) + v, c1.c + (c2.c - c1.c) * (d1 / d) - v}; if (ret[0] > ret[1]) std::swap(ret[0], ret[1]); return ret; } // 三角形の内接円 Circle incircle_of_triangle(const Point &pa, const Point &pb, const Point &pc) { coordinate_t a = (pb - pc).abs(), b = (pc - pa).abs(), c = (pa - pb).abs(); Point p = (pa * a + pb * b + pc * c) / (a + b + c); coordinate_t r = dist(Line(pa, pb), p); return Circle(p, r); } // 三角形の内接円 Circle incircle_of_triangle(const Polygon &poly) { assert((int)poly.size() == 3); const Point &pa = poly[0], &pb = poly[1], &pc = poly[2]; return incircle_of_triangle(pa, pb, pc); } // 三角形の外接円 Circle circumscribed_circle_of_triangle(const Point &pa, const Point &pb, const Point &pc) { Line l1 = Line(pa, pb).vertical_bisector(); Line l2 = Line(pa, pc).vertical_bisector(); Point p = cross_point(l1, l2); coordinate_t r = (pa - p).abs(); return Circle(p, r); } // 三角形の外接円 Circle circumscribed_circle_of_triangle(const Polygon &poly) { assert((int)poly.size() == 3); const Point &pa = poly[0], &pb = poly[1], &pc = poly[2]; return circumscribed_circle_of_triangle(pa, pb, pc); } // 凸包 Polygon convex_hull(std::vector<Point> ps) { int n = int(ps.size()); std::sort(ps.begin(), ps.end()); Polygon ret(2 * n); int k = 0; for (int i = 0; i < n; ret[k++] = ps[i++]) { while (k >= 2 && sgn(det(ret[k - 1] - ret[k - 2], ps[i] - ret[k - 2])) < 0) { k--; } } for (int i = n - 2, t = k + 1; i >= 0; ret[k++] = ps[i--]) { while (k >= t && sgn(det(ret[k - 1] - ret[k - 2], ps[i] - ret[k - 2])) < 0) { k--; } } ret.resize(k - 1); return ret; } // 最小包含円 Circle smallest_enclosing_circle(std::vector<Point> ps) { assert((int)ps.size() >= 2); std::random_device seed_gen; std::mt19937_64 rnd(seed_gen()); std::shuffle(ps.begin(), ps.end(), rnd); Circle ret((ps[0] + ps[1]) / 2, (ps[0] - ps[1]).abs() / 2); for (int i = 2; i < (int)ps.size(); i++) { if (ret.contain(ps[i])) continue; ret = Circle((ps[0] + ps[i]) / 2, (ps[0] - ps[i]).abs() / 2); for (int j = 1; j < i; j++) { if (ret.contain(ps[j])) continue; ret = Circle((ps[i] + ps[j]) / 2, (ps[i] - ps[j]).abs() / 2); for (int k = 0; k < j; k++) { if (ret.contain(ps[k])) continue; ret = circumscribed_circle_of_triangle(ps[i], ps[j], ps[k]); } } } return ret; } // 円cと多角形pの共通部分の面積を返す。 coordinate_t area_of_intersection(Circle c, Polygon p) { auto signed_area_of_triangle = [](Point a, Point b) -> coordinate_t { return det(a, b); }; auto signed_area_of_sector = [&c](Point a, Point b) -> coordinate_t { return c.r * c.r * (rotate(b, -a.arg()).arg()); }; auto is_in_circle = [&c](Point a) -> bool { return sgn(a.abs() - c.r) < 0; }; coordinate_t ret = 0; for (int i = 0; i < int(p.size()); i++) p[i] -= c.c; for (int i = 0; i < int(p.size()); i++) { const Point &a = p[i], &b = p[(i + 1) % int(p.size())]; if (!intersect(Segment(a, b), c)) { ret += is_in_circle(a) ? signed_area_of_triangle(a, b) : signed_area_of_sector(a, b); } else { std::vector<Point> ps = cross_points(Segment(a, b), c); Point s = ps[0], t = ps[1 % int(ps.size())]; if ((a < b) != (s < t)) std::swap(s, t); ret += is_in_circle(a) ? signed_area_of_triangle(a, s) : signed_area_of_sector(a, s); ret += signed_area_of_triangle(s, t); ret += is_in_circle(b) ? signed_area_of_triangle(t, b) : signed_area_of_sector(t, b); } } ret = std::fabs(ret); ret /= 2; return ret; } // 円cと多角形pの共通部分の面積を返す。 coordinate_t area_of_intersection(Polygon p, Circle c) { return area_of_intersection(c, p); } // 円c1と円c2の共通部分の面積を返す。 coordinate_t area_of_intersection(const Circle &c1, const Circle &c2) { if (sgn(c1.r + c2.r - (c1.c - c2.c).abs()) <= 0) { return 0; } if (sgn(std::fabs(c1.r - c2.r) - (c1.c - c2.c).abs()) >= 0) { return std::min(c1.area(), c2.area()); } auto unsigned_area_of_triangle = [](Circle c1, Circle c2, Point p) -> coordinate_t { return std::fabs(det(c2.c - c1.c, p - c1.c)); }; auto unsigned_area_of_sector = [](Circle c1, Circle c2, Point p) -> coordinate_t { return std::fabs(c1.r * c1.r * rotate(c2.c - c1.c, -(p - c1.c).arg()).arg()); }; Point p = cross_points(c1, c2)[0]; coordinate_t ret = 0; ret += unsigned_area_of_sector(c1, c2, p); ret += unsigned_area_of_sector(c2, c1, p); ret -= unsigned_area_of_triangle(c1, c2, p); return ret; } // 凸多角形polyを直線lで切断したときに、その左側にできる凸多角形。 Polygon convex_cut_left(const Polygon &poly, const Line &l) { assert(poly.is_convex()); Polygon ret; for (int i = 0; i < (int)poly.size(); i++) { if (ccw(l.a, l.b, poly[i]) != CLOCKWISE) { ret.push_back(poly[i]); } Segment s(poly[i], poly[(i + 1) % (int)poly.size()]); if (intersect(s, l)) { ret.push_back(cross_point(s, l)); } } return ret; } // 凸多角形polyを直線lで切断したときに、その右側にできる凸多角形。 Polygon convex_cut_right(const Polygon &poly, const Line &l) { assert(poly.is_convex()); Polygon ret; for (int i = 0; i < (int)poly.size(); i++) { if (ccw(l.a, l.b, poly[i]) != COUNTER_CLOCKWISE) { ret.push_back(poly[i]); } Segment s(poly[i], poly[(i + 1) % (int)poly.size()]); if (intersect(s, l)) { ret.push_back(cross_point(s, l)); } } return ret; } // 点pを通る円cの接線。接点を返す。 std::vector<Point> tangent_points(const Circle &c, const Point &p) { assert(sgn((p - c.c).abs() - c.r) >= 0); coordinate_t r = std::sqrt((c.c - p).abs() * (c.c - p).abs() - c.r * c.r); return cross_points(c, Circle(p, r)); } // 円c1と円c2の共通接線の本数。 int count_common_tangent(const Circle &c1, const Circle &c2) { if (sgn((c1.c - c2.c).abs() - (c1.r + c2.r)) > 0) { return 4; // do not cross } if (sgn((c1.c - c2.c).abs() - (c1.r + c2.r)) == 0) { return 3; // circumscribed } if (sgn((c1.c - c2.c).abs() - std::fabs(c1.r - c2.r)) > 0) { return 2; // intersects } if (sgn((c1.c - c2.c).abs() - std::fabs(c1.r - c2.r)) == 0) { return 1; // inscribed } return 0; } // 円c1と円c2の共通接線。円c1における接点を返す。 std::vector<Point> common_tangents(const Circle &c1, const Circle &c2) { std::vector<Point> ret, ret1, ret2; if (sgn((c1.c - c2.c).abs() - std::fabs(c1.r - c2.r)) >= 0) { coordinate_t d = (c1.c - c2.c).abs(); coordinate_t r = std::sqrt(d * d - (c1.r - c2.r) * (c1.r - c2.r) + c2.r * c2.r); ret1 = cross_points(c1, Circle(c2.c, r)); } if (sgn((c1.c - c2.c).abs() - (c1.r + c2.r)) >= 0) { Point p = c1.c + (c2.c - c1.c) * c1.r / (c1.r + c2.r); ret2 = tangent_points(c1, p); } std::merge(ret1.begin(), ret1.end(), ret2.begin(), ret2.end(), std::back_inserter(ret)); ret.erase(std::unique(ret.begin(), ret.end()), ret.end()); return ret; } std::pair<coordinate_t, std::pair<Point, Point>> closest_pair( std::vector<Point> ps) { std::sort(ps.begin(), ps.end(), [](Point a, Point b) { return sgn(a.x - b.x) < 0; }); std::vector<Point> memo(ps.size()); auto dfs = [&](auto dfs, int l, int r) -> std::pair<coordinate_t, std::pair<Point, Point>> { if (r - l < 2) return {1e18, {Point(), Point()}}; int m = (r + l) / 2; coordinate_t x = ps[m].x; auto l_res = dfs(dfs, l, m), r_res = dfs(dfs, m, r); auto [d, p] = (l_res.first < r_res.first ? l_res : r_res); std::inplace_merge(ps.begin() + l, ps.begin() + m, ps.begin() + r, [](Point a, Point b) { return sgn(a.y - b.y) < 0; }); int cur = 0; for (int i = l; i < r; i++) { if (std::fabs(ps[i].x - x) >= d) continue; for (int j = cur - 1; j >= 0; j--) { if (ps[i].y - memo[j].y >= d) break; coordinate_t new_d = (ps[i] - memo[j]).abs(); if (new_d < d) { d = new_d; p = {ps[i], memo[j]}; } } memo[cur++] = ps[i]; } return {d, p}; }; return dfs(dfs, 0, (int)ps.size()); } std::pair<coordinate_t, std::pair<Point, Point>> farthest_pair( std::vector<Point> ps) { ps = convex_hull(ps); std::pair<coordinate_t, std::pair<Point, Point>> ret = { 0, std::make_pair(ps[0], ps[0])}; int r = 0; for (int l = 0; l < (int)ps.size(); l++) { while (sgn((ps[l] - ps[r]).abs() - (ps[l] - ps[(r + 1) % (int)ps.size()]).abs()) < 0) { r++; if (r == (int)ps.size()) r = 0; } if (sgn(ret.first - (ps[l] - ps[r]).abs()) < 0) { ret.first = (ps[l] - ps[r]).abs(); ret.second = {ps[l], ps[r]}; } } return ret; } } // namespace geometry #pragma endregion void solve(){ using P=geometry::Point; int N; cin>>N; if(N==0){ cout<<1<<endl; return; } vi X(N),Y(N); rep(i,N) cin>>X[i]>>Y[i]; map<pii,int> mp; rep(i,N) mp[make_pair(X[i],Y[i])]=i; dsu UF(N); rep(i,N){ for(int a=-10;a<=10;a++){ for(int b=-10;b<=10;b++){ if(a==0 && b==0) continue; if(a*a+b*b>100) continue; if(mp.find(make_pair(X[i]+a,Y[i]+b))!=mp.end()) UF.merge(i,mp[make_pair(X[i]+a,Y[i]+b)]); } } } double ans=2; for(auto V:UF.groups()){ if(sz(V)==1) continue; vector<P> tmp; for(auto v:V) tmp.emplace_back(P(X[v],Y[v])); auto ret=geometry::farthest_pair(tmp); chmax(ans,ret.first+2); } cout<<fixed<<setprecision(12)<<ans<<endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }