結果
| 問題 |
No.96 圏外です。
|
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2016-04-17 21:07:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 345 ms / 5,000 ms |
| コード長 | 4,468 bytes |
| コンパイル時間 | 1,389 ms |
| コンパイル使用メモリ | 113,776 KB |
| 実行使用メモリ | 18,432 KB |
| 最終ジャッジ日時 | 2024-12-24 08:36:36 |
| 合計ジャッジ時間 | 5,895 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
class UnionFindTree
{
private:
int N;
int *rootnum;
int *rank;
int *unionnum;
public:
UnionFindTree(int n){
/*0からn-1までの要素をunionとしてもつ*/
N = n;
rootnum = new int[N];
rank = new int[N];
unionnum = new int[N];
for( int i = 0 ; i < N ; i++ ){
rootnum[i] = i;
rank[i] = 0;
unionnum[i] = 1;
}
}
int Find( int j ){
if( rootnum[j] == j ){
return j;
}
else{
return rootnum[j] = Find(rootnum[j]);
}
}
void Union( int i , int j ){
int x = Find(i);
int y = Find(j);
if( x == y ) return;
N--;
if( rank[x] < rank[y] ){
rootnum[y] = x;
unionnum[x] += unionnum[y];
}else{
rootnum[x] = y;
unionnum[y] += unionnum[x];
if( rank[x]==rank[y] ) rank[x]++;
}
}
int Num( int j ){
/*与えられた要素の入っている集合の要素数を答える*/
int x = Find(j);
return unionnum[x];
}
int UnionNum(){
/*集合の数を答える*/
return N;
}
~UnionFindTree(){
delete rootnum;
delete rank;
delete unionnum;
}
};
long long product( pair<int,int> p1, pair<int,int> p2, pair<int,int> p3 ){
pair<int,int> v1 = make_pair( p2.first-p1.first, p2.second-p1.second);
pair<int,int> v2 = make_pair( p3.first-p2.first, p3.second-p2.second);
return -(v2.first*(long long)v1.second-v2.second*(long long)v1.first);
}
vector< pair<int,int> > convex_hull( vector<pair<int,int> > &V){
if( V.size() <=2 ) return V;
int size = V.size();
sort(V.begin(),V.end());
vector<pair<int,int> > ret(size*2);
int retlen=0;
for( int i = 0 ; i <size; i++ ){
while( retlen >= 2 && product( ret[retlen-2],ret[retlen-1],V[i] ) <= 0 ) retlen--;
ret[retlen++]=V[i];
}
int underlen=retlen;
for( int i = size-2 ; i >= 0 ; i-- ){
while( retlen > underlen && product( ret[retlen-2],ret[retlen-1],V[i] ) <= 0 ) retlen--;
ret[retlen++]=V[i];
}
ret.resize(retlen);
return ret;
}
pair<int,int> points[120001];
vector< pair<int,int > > V[120001];
map<int, int> m[20011];
UnionFindTree uft(120001);
int main(){
int N;
cin >> N;
for( int i = 0 ; i < N ; i++ ){
V[i].clear();
cin >> points[i].first >> points[i].second;
m[points[i].first+10000][points[i].second+10000]=i+1;
}
if( N == 0 ){
printf("%.10f\n",1.0);
return 0;
}
for( int i = 0 ; i < N ; i++ ){
int x = points[i].first+10000;
int y = points[i].second+10000;
for( int x2 = x ; x2 <= x+10; x2++ ){
map<int,int>::iterator it=m[x2].lower_bound(y-10);
map<int,int>::iterator itEnd=m[x2].lower_bound(y+11);
for( ;it != itEnd; it++ ){
int y2=it->first;
int dx=x-x2;
int dy=y-y2;
if( dx*dx+dy*dy <= 100 ){
//cout << i <<" "<< it->second-1<<endl;
uft.Union(i,it->second-1);
}
}
}
}
for( int i = 0 ; i < N ; i++ ){
V[uft.Find(i)].push_back(points[i]);
}
long long maxDist = 0;
for( int i = 0 ; i <N; i++ ){
// for( int j = 0 ; j <(int) V[i].size(); j++ ){
// cout << V[i][j].first <<", "<< V[i][j].second<<"/";
// }
// cout << endl;
vector<pair<int,int> > convPoints = convex_hull(V[i]);
for( int j = 0 ; j < (int) convPoints.size(); j ++ ){
// cout << convPoints[j].first << "," << convPoints[j].second<<"/ ";
for( int k = j+1 ; k < (int) convPoints.size(); k++ ){
long long dx = convPoints[j].first-convPoints[k].first;
long long dy = convPoints[j].second-convPoints[k].second;
maxDist = max(maxDist,dx*dx+dy*dy);
}
}
// cout << endl;
}
printf("%.10f\n",2.0+sqrt((double)maxDist));
return 0;
}
yaoshimax