結果

問題 No.96 圏外です。
ユーザー gyouzasushigyouzasushi
提出日時 2022-08-31 01:10:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,532 ms / 5,000 ms
コード長 24,460 bytes
コンパイル時間 4,167 ms
コンパイル使用メモリ 246,020 KB
実行使用メモリ 21,776 KB
最終ジャッジ日時 2024-04-25 07:54:50
合計ジャッジ時間 26,423 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 27 ms
5,376 KB
testcase_06 AC 44 ms
6,016 KB
testcase_07 AC 81 ms
6,072 KB
testcase_08 AC 111 ms
6,656 KB
testcase_09 AC 167 ms
7,296 KB
testcase_10 AC 313 ms
7,680 KB
testcase_11 AC 359 ms
8,960 KB
testcase_12 AC 396 ms
11,008 KB
testcase_13 AC 830 ms
10,496 KB
testcase_14 AC 1,009 ms
12,544 KB
testcase_15 AC 1,463 ms
12,800 KB
testcase_16 AC 1,808 ms
15,488 KB
testcase_17 AC 1,810 ms
18,816 KB
testcase_18 AC 2,523 ms
17,792 KB
testcase_19 AC 2,532 ms
17,664 KB
testcase_20 AC 1,116 ms
17,768 KB
testcase_21 AC 555 ms
18,320 KB
testcase_22 AC 636 ms
20,700 KB
testcase_23 AC 818 ms
21,776 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 1,058 ms
15,360 KB
testcase_26 AC 1,645 ms
17,792 KB
testcase_27 AC 1,303 ms
16,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#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())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
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;
}
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;
}
#pragma region UnionFind
#include <vector>
struct UnionFind {
    int n;
    std::vector<int> data;
    UnionFind(int _n) : n(_n), data(_n, -1) {
    }
    int root(int x) {
        return (data[x] < 0) ? x : data[x] = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return -data[root(x)];
    }
    std::vector<std::vector<int>> groups() {
        std::vector<int> root_buf(n), group_size(n);
        for (int i = 0; i < n; i++) {
            root_buf[i] = root(i);
            group_size[root_buf[i]]++;
        }
        std::vector<std::vector<int>> ret(n);
        for (int i = 0; i < n; i++) {
            ret[i].reserve(group_size[i]);
        }
        for (int i = 0; i < n; i++) {
            ret[root_buf[i]].push_back(i);
        }
        ret.erase(std::remove_if(
                      ret.begin(), ret.end(),
                      [&](const std::vector<int> &v) { return v.empty(); }),
                  ret.end());
        return ret;
    }
};
#pragma endregion
#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
int main() {
    int n;
    cin >> n;
    if (n == 0) {
        cout << 1 << '\n';
        return 0;
    }
    vector<int> x(n), y(n);
    const int offset = 11000;
    vector<unordered_map<int, int>> st(22000);
    rep(i, n) {
        cin >> x[i] >> y[i];
        st[x[i] + offset][y[i]] = i;
    }
    UnionFind uf(n);
    rep(i, n) {
        for (int ny = y[i] - 10; ny <= y[i] + 10; ny++) {
            for (int nx = x[i] - 10; nx <= x[i] + 10; nx++) {
                if ((x[i] - nx) * (x[i] - nx) + (y[i] - ny) * (y[i] - ny) <=
                        100 &&
                    st[nx + offset].count(ny)) {
                    int j = st[nx + offset][ny];
                    uf.unite(i, j);
                }
            }
        }
    }
    double ans = 2;
    for (auto &v : uf.groups()) {
        vector<geometry::Point> ps;
        for (int i : v) ps.emplace_back(x[i], y[i]);
        chmax(ans, geometry::farthest_pair(ps).first + 2);
    }
    cout << fixed << setprecision(20);
    cout << ans << '\n';
}
0