結果

問題 No.96 圏外です。
ユーザー pekempeypekempey
提出日時 2016-02-18 07:24:20
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,808 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 175,012 KB
実行使用メモリ 12,632 KB
最終ジャッジ日時 2023-10-23 17:45:43
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 39 ms
11,428 KB
testcase_23 AC 39 ms
11,428 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:95:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   95 |         rep(i, n) scanf("%lld %lld", &x[i], &y[i]);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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 = 0;
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);
	rep(i, n) scanf("%lld %lld", &x[i], &y[i]);
	rep(i, n - 1) {
		if (hypot2(x[i + 1] - x[i], y[i + 1] - y[i]) <= 100) uf.merge(i, i + 1);
	}
	
	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