結果

問題 No.96 圏外です。
ユーザー antaanta
提出日時 2018-04-06 18:51:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 5,000 ms
コード長 4,040 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 186,336 KB
実行使用メモリ 11,420 KB
最終ジャッジ日時 2023-09-08 18:02:13
合計ジャッジ時間 5,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 6 ms
4,380 KB
testcase_06 AC 8 ms
4,384 KB
testcase_07 AC 11 ms
4,384 KB
testcase_08 AC 14 ms
4,384 KB
testcase_09 AC 19 ms
4,400 KB
testcase_10 AC 25 ms
4,736 KB
testcase_11 AC 30 ms
5,460 KB
testcase_12 AC 37 ms
6,024 KB
testcase_13 AC 49 ms
6,496 KB
testcase_14 AC 57 ms
7,632 KB
testcase_15 AC 72 ms
7,788 KB
testcase_16 AC 85 ms
9,596 KB
testcase_17 AC 96 ms
11,048 KB
testcase_18 AC 104 ms
10,740 KB
testcase_19 AC 103 ms
10,872 KB
testcase_20 AC 101 ms
10,064 KB
testcase_21 AC 83 ms
10,144 KB
testcase_22 AC 106 ms
11,236 KB
testcase_23 AC 112 ms
11,420 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 69 ms
8,616 KB
testcase_26 AC 87 ms
10,188 KB
testcase_27 AC 75 ms
9,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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-hull
		while (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-hull
		while (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;
}
0