結果

問題 No.96 圏外です。
ユーザー Yang33Yang33
提出日時 2018-04-22 21:09:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 5,000 ms
コード長 5,657 bytes
コンパイル時間 3,082 ms
コンパイル使用メモリ 185,916 KB
実行使用メモリ 117,472 KB
最終ジャッジ日時 2023-09-09 14:08:25
合計ジャッジ時間 8,154 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
96,968 KB
testcase_01 AC 94 ms
97,020 KB
testcase_02 AC 94 ms
97,004 KB
testcase_03 AC 93 ms
96,972 KB
testcase_04 AC 95 ms
97,756 KB
testcase_05 AC 97 ms
97,856 KB
testcase_06 AC 99 ms
97,988 KB
testcase_07 AC 102 ms
98,152 KB
testcase_08 AC 106 ms
98,492 KB
testcase_09 AC 112 ms
98,860 KB
testcase_10 AC 116 ms
99,480 KB
testcase_11 AC 123 ms
100,236 KB
testcase_12 AC 131 ms
101,320 KB
testcase_13 AC 143 ms
101,192 KB
testcase_14 AC 151 ms
103,080 KB
testcase_15 AC 169 ms
103,356 KB
testcase_16 AC 180 ms
105,540 KB
testcase_17 AC 203 ms
108,076 KB
testcase_18 AC 207 ms
107,016 KB
testcase_19 AC 205 ms
107,048 KB
testcase_20 AC 205 ms
108,744 KB
testcase_21 AC 218 ms
117,472 KB
testcase_22 AC 270 ms
117,388 KB
testcase_23 AC 278 ms
117,460 KB
testcase_24 AC 94 ms
97,060 KB
testcase_25 AC 167 ms
104,900 KB
testcase_26 AC 188 ms
107,008 KB
testcase_27 AC 179 ms
105,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[9] = { 0, 0, 1, -1, 1, 1, -1, -1,0 };    int DY[9] = { 1, -1, 0, 0, 1, -1, 1, -1,0 };

/* -----  2018/04/19  Problem: yukicoder 096  / Link: http://yukicoder.me/problems/no/096  ----- */
/* ------問題------

no64

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

struct UnionFind {
	vector<int> data;
	UnionFind(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 same(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)]; }
};

const long double EPS = 1e-9;
using Double = long double;
typedef struct Point {
	Double x, y;
	Point(Double x_, Double y_) : x(x_), y(y_) {}

	bool operator < (const Point& a) const {
		return fabs(x - a.x) < EPS ? y + EPS < a.y : x + EPS < a.x;
	}

	bool operator > (const Point& a) const {
		return a < *this;
	}

	bool operator == (const Point& a) const {
		return !(a < *this) && !(a > *this);
	}

	Point operator + (const Point& a) const {
		return Point(x + a.x, y + a.y);
	}

	Point operator - (const Point& a) const {
		return Point(x - a.x, y - a.y);
	}

	Point operator * (const Point& a) const {
		return Point(x * a.x, y * a.y);
	}

	Point operator / (const Point& a) const {
		return Point(x / a.x, y / a.y);
	}

	Point operator * (const Double& d) const {
		return Point(x * d, y * d);
	}

	Point operator / (const Double& d) const {
		return Point(x / d, y / d);
	}
} Vector;
Double cross(const Vector& a, const Vector& b) {
	return a.x * b.y - a.y * b.x;
}
Double norm(const Point& a) {
	return a.x * a.x + a.y * a.y;
}
Double abs(const Point& a) {
	return sqrt(norm(a));
}
Double dot(const Vector& a, const Vector& b) {
	return a.x * b.x + a.y * b.y;
}
struct Polygon {
	vector< Point > vert;
	Polygon(int n = 3) : vert(n, Point(0, 0)) {}

	Double area() const {
		Double res = 0;
		int v_size = size();

		FOR(i, 0, v_size) res += cross(at(i), at(i + 1));

		return fabs(res) / 2.;
	}

	Point at(int i) const {
		i %= size();
		return vert[i];
	}

	int size() const { return SZ(vert); }
};

int ccw(const Point& a, const Point& b, const Point&  c) {
	Vector ba = b - a, ca = c - a;
	if (cross(ba, ca) > EPS) return +1; // ccw
	if (cross(ba, ca) < -EPS) return -1; // cw
	if (dot(ba, ca) < -EPS) return +2; // c-a-b
	if (abs(ba) + EPS < abs(ca)) return -2; // a-b-c
	return 0; // a-c-b
}
Polygon convex_hull(vector< Point > vp) {
	if (SZ(vp) <= 1) {
		Polygon ret;
		ret.vert = vp;
		return ret;
	}
	int n = SZ(vp), k = 0;
	sort(ALL(vp));
	vector< Point > ch(2 * n, Point(0, 0));

	for (int i = 0; i < n; ch[k++] = vp[i++]) {
		while (k >= 2 && ccw(ch[k - 2], ch[k - 1], vp[i]) <= 0) --k;
	}

	for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = vp[i--]) {
		while (k >= t && ccw(ch[k - 2], ch[k - 1], vp[i]) <= 0) --k;
	}

	Polygon res(k - 1);
	FOR(i, 0, k - 1) res.vert[i] = ch[i];
	return res;
}
pair< PII, Double > caliper(const Polygon& p) {
	int n = SZ(p);
	if (n == 2) {
		return make_pair(PII(0, 1), abs(p.at(0) - p.at(1)));
	}
	int i = 0, j = 0;
	FOR(k, 0, n) {
		if (!(p.at(i) < p.at(k))) i = k;
		if (p.at(j) < p.at(k)) j = k;
	}
	PII pp(-1, -1);
	Double res = 0;
	int si = i, sj = j;
	while (i != sj || j != si) {
		Double cur = abs(p.at(i) - p.at(j));

		if (res + EPS < cur) {
			res = cur;
			pp = PII(i, j);
		}
		int di = (i + 1) % n;
		int dj = (j + 1) % n;
		if (cross(p.at(di) - p.at(i), p.at(dj) - p.at(j)) < 0) i = di;
		else j = dj;
	}

	return make_pair(pp, res);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N; cin >> N;
	VI x(N), y(N);
	vector<VVI>backet(2001, VVI(2001));

	FOR(i, 0, N) {
		cin >> x[i] >> y[i];
		x[i] += 10000, y[i] += 10000;
		backet[x[i] / 10][y[i] / 10].push_back(i);
	}
	UnionFind uf(N);

	FOR(i, 0, 2001) {
		FOR(j, 0, 2001) {
			for (auto id : backet[i][j]) {
				FOR(k, 0, 9) {
					int ny = i + DY[k], nx = j + DX[k];
					if (0 <= ny && ny < 2001 && 0 <= nx && nx < 2001) {
						for (auto nid : backet[ny][nx]) {
							int dist = pow(x[id] - x[nid], 2) + pow(y[id] - y[nid], 2);
							if (dist <= 100) {
								uf.unionSet(id, nid);
							}
						}
					}
				}
			}
		}
	}
	VVI groups(N);
	FOR(i, 0, N) {
		groups[uf.root(i)].push_back(i);
	}


	Double ans = 1;
	FOR(i, 0, SZ(groups)) {
		vector<Point>vp;
		FOR(j, 0, SZ(groups[i])) {
			vp.emplace_back(x[groups[i][j]], y[groups[i][j]]);
		}
		Polygon ch = convex_hull(vp);
		if (SZ(ch.vert) > 1) {
			auto ret = caliper(ch);
			ans = max(ans, ret.second + 2);
		}
		else if (SZ(ch.vert) == 1) {
			ans = max(ans, (Double)2);
		}
	}




	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}
0