結果

問題 No.96 圏外です。
ユーザー chocoruskchocorusk
提出日時 2019-12-13 22:22:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,187 ms / 5,000 ms
コード長 3,342 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 126,576 KB
実行使用メモリ 12,944 KB
最終ジャッジ日時 2023-09-09 23:47:22
合計ジャッジ時間 29,396 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,544 KB
testcase_01 AC 3 ms
7,964 KB
testcase_02 AC 3 ms
6,572 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 30 ms
8,164 KB
testcase_05 AC 53 ms
6,812 KB
testcase_06 AC 88 ms
7,616 KB
testcase_07 AC 136 ms
7,472 KB
testcase_08 AC 197 ms
7,344 KB
testcase_09 AC 279 ms
7,660 KB
testcase_10 AC 397 ms
8,180 KB
testcase_11 AC 510 ms
9,280 KB
testcase_12 AC 647 ms
8,904 KB
testcase_13 AC 890 ms
9,328 KB
testcase_14 AC 1,082 ms
10,028 KB
testcase_15 AC 1,376 ms
10,756 KB
testcase_16 AC 1,636 ms
11,220 KB
testcase_17 AC 1,893 ms
12,392 KB
testcase_18 AC 2,033 ms
12,004 KB
testcase_19 AC 2,035 ms
12,144 KB
testcase_20 AC 2,057 ms
11,700 KB
testcase_21 AC 1,532 ms
12,068 KB
testcase_22 AC 2,187 ms
12,892 KB
testcase_23 AC 2,089 ms
12,944 KB
testcase_24 AC 3 ms
6,580 KB
testcase_25 AC 1,290 ms
11,024 KB
testcase_26 AC 1,715 ms
12,052 KB
testcase_27 AC 1,447 ms
11,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
//typedef pair<int, int> P;
#define EPS 1e-10
double add(double a, double b){
    if(abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
    return a+b;
}
struct P{
    double x, y;
    P() {}
    P(double x, double y): x(x), y(y){
    }
    P operator+ (P p){
        return P(add(x, p.x), add(y, p.y));
    }
    P operator- (P p){
        return P(add(x, -p.x), add(y, -p.y));
    }
    P operator* (double d){
        return P(x*d, y*d);
    }
    double dot(P p){
        return add(x*p.x, y*p.y);
    }
    double det(P p){
        return add(x*p.y, -y*p.x);
    }
    bool operator< (const P& p) const{
        if(abs(x-p.x)>EPS){
            return x<p.x;
        }else{
            return y<p.y-EPS;
        }
    }
	bool operator== (const P& p) const{
        if(abs(x-p.x)<EPS && abs(y-p.y)<EPS) return true;
        else return false;
    }
};
double dist(P p1, P p2){
  return sqrt((p1-p2).dot(p1-p2));
}
vector<P> convex_hull(vector<P> ps){
	int n=ps.size();
  sort(ps.begin(), ps.end());
  int k=0;
  vector<P> qs(n*2);
  for(int i=0; i<n; i++){
    while(k>1 && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2, t=k; i>=0; i--){
    while(k>t && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}
double maxdist(vector<P> v){
	int n=v.size();
	double ret=0;
	int i=0, j=0;
	for(int k=0; k<n; k++){
		if(v[k]<v[i]) i=k;
		if(v[j]<v[k]) j=k;
	}
	int i0=i, j0=j;
	do{
		ret=max(ret, dist(v[i], v[j]));
		P r1=v[(i+1)%n]-v[i], r2=v[(j+1)%n]-v[j];
		if(r1.det(r2)>=0) j=(j+1)%n;
		else i=(i+1)%n;
	}while(i0!=i || j0!=j);
	return ret;
}
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
	int n;
	cin>>n;
	if(n==0){
		cout<<1<<endl;
		return 0;
	}
	P p[120020];
	for(int i=0; i<n; i++){
		cin>>p[i].x>>p[i].y;
	}
	sort(p, p+n);
	unionfind uf(n);
	vector<P> w;
	for(int i=-10; i<=10; i++){
		for(int j=-10; j<=10; j++){
			if(i*i+j*j<=100){
				w.push_back(P(i, j));
			}
		}
	}
	for(int i=0; i<n; i++){
		for(auto q:w){
			int k=lower_bound(p, p+n, p[i]+q)-p;
			if(k<n && p[k]==p[i]+q) uf.unite(i, k);
		}
	}
	vector<P> v[120020];
	for(int i=0; i<n; i++) v[uf.find(i)].push_back(p[i]);
	double ans=0;
	for(int i=0; i<n; i++){
		if(v[i].size()<=1) continue;
		ans=max(ans, maxdist(convex_hull(v[i])));
	}
	printf("%.7lf\n", ans+2);
	return 0;
}
0