結果
問題 | No.96 圏外です。 |
ユーザー |
![]() |
提出日時 | 2020-11-18 16:34:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 5,000 ms |
コード長 | 4,040 bytes |
コンパイル時間 | 2,295 ms |
コンパイル使用メモリ | 189,352 KB |
実行使用メモリ | 11,552 KB |
最終ジャッジ日時 | 2024-07-23 09:05:52 |
合計ジャッジ時間 | 5,170 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include "bits/stdc++.h"using namespace std;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }struct UnionFind {vector<int> data;void init(int n) { data.assign(n, -1); }bool unionSet(int x, int y) {x = root(x); y = root(y);if (x != y) {if (data[y] < data[x]) swap(x, y);data[x] += data[y]; data[y] = x;}return x != y;}bool findSet(int x, int y) { return root(x) == root(y); }int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }int size(int x) { return -data[root(x)]; }};struct P {typedef int T; typedef ll T2; //T2は{a*b | a:T, b:T}を含むタイプT x, y;P(T x_, T y_) : x(x_), y(y_) {}P() : x(0), y(0) {}};inline bool operator==(const P& a, const P& b) { return a.x == b.x && a.y == b.y; }inline bool operator<(const P& a, const P& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }inline P operator+(const P& a, const P& b) { return P(a.x + b.x, a.y + b.y); }inline P operator-(const P& a, const P& b) { return P(a.x - b.x, a.y - b.y); }inline P operator-=(P& a, const P& b) { a.x -= b.x, a.y -= b.y; return a; }inline P::T2 cross(const P& a, const P& b) { return (P::T2)a.x*b.y - (P::T2)a.y*b.x; }inline P::T2 dot(const P& a, const P& b) { return (P::T2)a.x*b.x + (P::T2)a.y*b.y; }inline P::T2 norm(const P& a) { return (P::T2)a.x*a.x + (P::T2)a.y*a.y; }ostream& operator<<(ostream& out, const P& x) { out << "(" << x.x << ", " << x.y << ")"; return out; }inline int ccw(const P& a, const P& b, const P& c) {int ax = b.x - a.x, ay = b.y - a.y, bx = c.x - a.x, by = c.y - a.y;P::T2 t = (P::T2)ax*by - (P::T2)ay*bx;if (t > 0) return 1;if (t < 0) return -1;if ((P::T2)ax*bx + (P::T2)ay*by < 0) return +2;if ((P::T2)ax*ax + (P::T2)ay*ay < (P::T2)bx*bx + (P::T2)by*by) return -2;return 0;}vector<P> convex_hull(vector<P> ps) {if ((int)ps.size() <= 1) return ps;int n = ps.size(), k = 0;sort(ps.begin(), ps.end());vector<P> ch(2 * n);for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hullwhile (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hullwhile (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;ch.resize(k - 1);return ch;}int main() {int N;while (~scanf("%d", &N)) {vector<pair<int, int> > points(N);for (int i = 0; i < N; ++ i)scanf("%d%d", &points[i].first, &points[i].second);sort(points.begin(), points.end());const int D = 10, W = 10000, H = 10000;UnionFind uf;uf.init(N);{vector<vector<int>> ids(D + 1, vector<int>(H * 2 + 1, -1));auto get = [&](int x, int y) -> int& {x %= D + 1;if (x < 0) x += D + 1;return ids[x][y + H];};int pi = 0, qi = 0;rer(x, -W, W) {for (; qi != N && points[qi].first == x - D - 1; ++ qi)get(x - D - 1, points[qi].second) = -1;for (; pi != N && points[pi].first == x; ++ pi) {int y = points[pi].second;rer(dx, -D, 0) {rer(dy, -D, D) {if (dx * dx + dy * dy > D * D || y + dy < -H || y + dy > H) continue;int pj = get(x + dx, y + dy);if (pj != -1)uf.unionSet(pi, pj);}}get(x, y) = pi;}}}vector<vector<P>> ccs(N);rep(i, N) ccs[uf.root(i)].emplace_back(points[i].first, points[i].second);double ans = 1;for (auto &cc : ccs) if(!cc.empty()) {cc = convex_hull(cc);ll maxd = 0;rep(i, cc.size()) rep(j, i) {amax(maxd, norm(cc[i] - cc[j]));}amax(ans, sqrt((double)maxd) + 2);}printf("%.10f\n", ans);}return 0;}