結果
問題 | No.96 圏外です。 |
ユーザー |
![]() |
提出日時 | 2015-04-10 22:28:59 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 354 ms / 5,000 ms |
コード長 | 2,944 bytes |
コンパイル時間 | 1,919 ms |
コンパイル使用メモリ | 172,528 KB |
実行使用メモリ | 109,924 KB |
最終ジャッジ日時 | 2024-12-24 08:12:33 |
合計ジャッジ時間 | 7,521 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include "bits/stdc++.h"using namespace std;typedef complex<double> P;namespace std {bool operator < (const P& a, const P& b) {return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);}}#define EPS 1e-8struct C {P p; double r;C(const P &p, double r) : p(p), r(r) { }};bool xy_less(const P& a, const P& b) {if (abs(a.imag() - b.imag()) < EPS) return (a.real() < b.real());return (a.imag() < b.imag());}double ccw(P a, P b, P c) {return (conj(b - a)*(c - a)).imag();}template<class IN>void walk_rightside(IN begin, IN end, vector<P>& v) {IN cur = begin;v.push_back(*cur++);vector<P>::size_type s = v.size();v.push_back(*cur++);while (cur != end) {if (v.size() == s || ccw(v[v.size() - 2], v.back(), *cur) > EPS)v.push_back(*cur++);elsev.pop_back();}v.pop_back();}vector<P> convex_hull(vector<P> v) {if (v.size() <= 1)return v; // EXCEPTIONALsort(v.begin(), v.end(), xy_less);vector<P> cv;walk_rightside(v.begin(), v.end(), cv);walk_rightside(v.rbegin(), v.rend(), cv);return cv;}vector<int> box[2004][2004];vector<P> p2[130002];int unidp[130002];int findunidp(int a){if (unidp[a] < 0) return a;else return unidp[a] = findunidp(unidp[a]);}bool connect(int a, int b){a = findunidp(a);b = findunidp(b);if (a == b) return false;unidp[a] += unidp[b];unidp[b] = a;return true;}int main(){int N;cin >> N;vector<P> ps;for (int i = 0; i < N; i++){int X, Y;cin >> X >> Y;ps.push_back(P(X + 10000, Y + 10000));unidp[i] = -1;}if (N == 0){cout << 1 << endl;return 0;}for (int i = 0; i < N; i++){int Xb = (int)(ps[i].real()) / 10 + 1;int Yb = (int)(ps[i].imag()) / 10 + 1;for (int dy = -1; dy <= 1; dy++){for (int dx = -1; dx <= 1; dx++){int nXb = Xb + dx;int nYb = Yb + dy;for (int j : box[nXb][nYb]){if (abs(ps[i] - ps[j]) <= 10){connect(i, j);}}}}box[Xb][Yb].push_back(i);}for (int i = 0; i < N; i++){p2[findunidp(i)].push_back(ps[i]);}double ans = 0;for (int i = 0; i < N; i++){if (p2[i].size() < 2) continue;vector<P> p3 = convex_hull(p2[i]);int M = p3.size();int p = 0;int q = 0;if (M < 50){for (int a = 0; a < M; a++){for (int b = a + 1; b < M; b++){double d1 = abs(p3[a] - p3[b]);ans = max(d1, ans);}}}else{vector<double> dist(M, 0);for (int j = 0; j < M; j++){while (true){q = p + 1; q %= M;double d1 = abs(p3[j] - p3[p]);double d2 = abs(p3[j] - p3[q]);ans = max(ans, d2);dist[j] = max(dist[j], d1);if (d1 >= d2) break;p = q;}while (true){int k = j - 1;if (k < 0){break;}double d = abs(p3[k] - p3[p]);if (dist[k] < d){dist[k] = d;j = k;}else break;}}}}ans += 2;printf("%.14f\n", ans);}