結果
| 問題 |
No.96 圏外です。
|
| コンテスト | |
| ユーザー |
nodchip
|
| 提出日時 | 2014-12-07 20:01:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,615 bytes |
| コンパイル時間 | 1,052 ms |
| コンパイル使用メモリ | 125,400 KB |
| 実行使用メモリ | 14,008 KB |
| 最終ジャッジ日時 | 2024-06-11 16:20:23 |
| 合計ジャッジ時間 | 15,160 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 1 -- * 17 |
ソースコード
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <string>
#include <fstream>
#include <ios>
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdlib>
#include <cstddef>
#include <cstdarg>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <cwctype>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
typedef long long ll;
typedef unsigned long long ull;
#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ABS(a) ((a)>0?(a):-(a))
template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; }
template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; }
template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; }
template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; }
typedef complex<double> P;
const double INF = 1e12;
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);
}
}
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}
struct L : public vector<P> {
L(const P &a, const P &b) {
push_back(a); push_back(b);
}
};
typedef vector<P> G;
struct C {
P p; double r;
C(const P &p, double r) : p(p), r(r) { }
};
int ccw(P a, P b, P c) {
b -= a; c -= a;
if (cross(b, c) > 0) return +1; // counter clockwise
if (cross(b, c) < 0) return -1; // clockwise
if (dot(b, c) < 0) return +2; // c--a--b on line
if (norm(b) < norm(c)) return -2; // a--b--c on line
return 0;
}
vector<P> convex_hull(vector<P> 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;
}
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -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)];
}
};
bool cmp_x(const P& p, const P& q) {
if (p.real() != q.real()) return p.real() < q.real();
return p.imag() < q.imag();
}
int main() {
std::ios::sync_with_stdio(false);
int N;
cin >> N;
vector<P> pos;
REP(n, N) {
int x, y;
cin >> x >> y;
pos.push_back(P(x, y));
}
UnionFind uf(N);
REP(i, N) {
REP(j, i) {
if (abs(pos[i] - pos[j]) < 10 + EPS) {
uf.unionSet(i, j);
}
}
}
map<int, vector<P> > points;
REP(i, N) {
points[uf.root(i)].push_back(pos[i]);
}
double answer = 1.0;
if (N) {
answer = 2.0;
}
for (const auto& connected : points) {
vector<P> qs = convex_hull(connected.second);
int n = qs.size();
if (n == 1) {
continue;
}
if (n == 2) {
MAX_UPDATE(answer, abs(qs[0] - qs[1]) + 2.0);
continue;
}
int i = 0;
int j = 0;
for (int k = 0; k < n; ++k) {
if (!cmp_x(qs[i], qs[k])) i = k;
if (cmp_x(qs[j], qs[k])) j = k;
}
int si = i, sj = j;
while (i != sj || j != si) {
MAX_UPDATE(answer, abs(qs[i] - qs[j]) + 2.0);
if (cross(qs[(i + 1) % n] - qs[i], qs[(j + 1) % n] - qs[j]) < 0) {
i = (i + 1) % n;
}
else {
j = (j + 1) % n;
}
}
}
printf("%.20f\n", answer);
}
nodchip