結果

問題 No.96 圏外です。
ユーザー pekempeypekempey
提出日時 2016-02-18 07:38:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 3,108 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 162,280 KB
実行使用メモリ 111,856 KB
最終ジャッジ日時 2023-08-25 21:50:26
合計ジャッジ時間 6,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
99,136 KB
testcase_01 AC 38 ms
99,208 KB
testcase_02 AC 39 ms
99,144 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 40 ms
99,400 KB
testcase_05 AC 42 ms
99,788 KB
testcase_06 AC 45 ms
99,900 KB
testcase_07 AC 46 ms
100,152 KB
testcase_08 AC 50 ms
100,384 KB
testcase_09 AC 55 ms
100,900 KB
testcase_10 AC 61 ms
101,472 KB
testcase_11 AC 67 ms
102,492 KB
testcase_12 AC 74 ms
103,668 KB
testcase_13 AC 89 ms
104,124 KB
testcase_14 AC 96 ms
105,924 KB
testcase_15 AC 121 ms
106,860 KB
testcase_16 AC 136 ms
108,916 KB
testcase_17 AC 138 ms
111,432 KB
testcase_18 AC 160 ms
111,132 KB
testcase_19 AC 162 ms
111,444 KB
testcase_20 AC 123 ms
108,976 KB
testcase_21 AC 161 ms
111,856 KB
testcase_22 AC 157 ms
110,652 KB
testcase_23 AC 169 ms
110,672 KB
testcase_24 AC 39 ms
99,200 KB
testcase_25 AC 108 ms
107,788 KB
testcase_26 AC 130 ms
110,536 KB
testcase_27 AC 115 ms
108,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;

typedef double D;
typedef complex<D> P;
const D eps = 1e-8;
D dot(P a, P b) { return real(conj(a) * b); }
D cross(P a, P b) { return imag(conj(a) * b); }

vector<P> convexfull(vector<P> &ps) {
	auto comp = [](P a, P b) {
		if (a.real() != b.real()) return a.real() < b.real();
		return a.imag() < b.imag();
	};
	int n = ps.size();
	sort(ps.begin(), ps.end(), comp);
	int k = 0;
	vector<P> qs(n * 2);
	for (int i = 0; i < n; i++) {
		while (k > 1 && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	for (int i = n - 2, t = k; i >= 0; i--) {
		while (k > t && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

double farthest(vector<P> &ps) {
	auto qs = convexfull(ps);
	int n = qs.size();
	if (n == 2) return abs(qs[0] - qs[1]);
	auto comp = [](P a, P b) {
		if (a.real() != b.real()) return a.real() < b.real();
		return a.imag() < b.imag();
	};
	int i = 0, j = 0;
	for (int k = 0; k < n; k++) {
		if (!comp(qs[i], qs[k])) i = k;
		if (comp(qs[j], qs[k])) j = k;
	}
	double ret = 0;
	int si = i, sj = j;
	while (i != sj || j != si) {
		ret = max(ret, abs(qs[i] - qs[j]));
		if (cross(qs[(i + 1) % n] - qs[i], qs[(j + 1) % n] - qs[j]) < 0) {
			i = (i + 1) % n;
		} else {
			j = (j + 1) % n;
		}
	}
	return ret;
}

struct UnionFind {
	vector<int> parent, size;
	UnionFind(int n) : parent(n), size(n, 1) { for (int i = 0; i < n; i++) parent[i] = i; }
	int operator[](int x) { return parent[x] == x ? x : (parent[x] = operator[](parent[x])); }
	bool merge(int x, int y) {
		if ((x = operator[](x)) == (y = operator[](y))) return false;
		parent[x] = parent[y] = size[x] > size[y] ? parent[x] : parent[y];
		size[x] = size[y] = size[x] + size[y];
		return true;
	}
};

ll hypot2(ll x, ll y) {
	return x * x + y * y;
}

int main() {
	int n;
	cin >> n;
	UnionFind uf(n);

	if (n == 0) {
		cout << 1 << endl;
		return 0;
	} else if (n == 1) {
		cout << 2 << endl;
		return 0;
	}

	vector<ll> x(n);
	vector<ll> y(n);
	static vector<int> bucket[2020][2020];
	rep(i, n) {
		scanf("%lld %lld", &x[i], &y[i]);
		x[i] += 10010;
		y[i] += 10010;
		bucket[x[i] / 10][y[i] / 10].push_back(i);
	}

	rep(i, n) {
		for (int dy = -1; dy <= 1; dy++) {
			for (int dx = -1; dx <= 1; dx++) {
				int bx = x[i] / 10;
				int by = y[i] / 10;
				for (int j : bucket[bx + dx][by + dy]) {
					if (hypot2(x[j] - x[i], y[j] - y[i]) <= 100) uf.merge(i, j);
				}
			}
		}
	}
	
	vector<vector<P>> ps(n);
	rep(i, n) ps[uf[i]].emplace_back(x[i], y[i]);

	double ans = 0;
	rep(i, n) if (!ps[i].empty()) chmax(ans, farthest(ps[i]));
	ans += 2;
	printf("%.20f\n", ans);

	return 0;
}
0