結果

問題 No.96 圏外です。
ユーザー shimomireshimomire
提出日時 2014-12-08 00:17:00
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 5,159 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 137,268 KB
実行使用メモリ 12,152 KB
最終ジャッジ日時 2023-09-02 11:31:12
合計ジャッジ時間 8,886 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,880 KB
testcase_01 AC 4 ms
4,472 KB
testcase_02 AC 3 ms
4,492 KB
testcase_03 AC 3 ms
4,420 KB
testcase_04 AC 14 ms
4,940 KB
testcase_05 AC 23 ms
5,188 KB
testcase_06 AC 36 ms
5,464 KB
testcase_07 AC 60 ms
5,996 KB
testcase_08 AC 83 ms
6,428 KB
testcase_09 AC 119 ms
7,056 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>// c
#include <ctime>
#include <iostream>// io
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>// container
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <algorithm>// other
#include <utility>
#include <complex>
#include <numeric>
#include <functional>
#include <random>
#include <regex>

using namespace std;
typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define FOR(i,l,r) for(int i=(int)l;i<(int)r;++i)
#define REP(i,n) FOR(i,0,n)
#define FORr(i,l,r) for(int i=(int)r-1;i>=(int)l;--i)
#define REPr(i,n) FORr(i,0,n)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end())
//debug
#define DUMP(x)  cerr << #x << " = " << (x)
#define LINE()    cerr<< " (L" << __LINE__ << ")"

template<typename T,typename U> T pmod(T x,U M){return (x%M+M)%M;}

struct UnionFind{
    vector<int> par,rank,ss;int size;
    UnionFind(int n){
        REP(i,n) par.push_back(i);
        rank = vector<int>(n);ss=vector<int>(n,1);size=n;
    }
    int root(int x){
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    void unite(int x,int y){
        x = root(x);y = root(y);
        if(x==y)return;
        if(rank[x] < rank[y]){
            par[x] = y;ss[y]+=ss[x];
        }else{
            par[y] = x;ss[x]+=ss[y];
        }
        if(rank[x] == rank[y]) rank[x]++;
        size--;
    }
    int getS(int x){
        return ss[root(x)];
    }
};

// must template
typedef int D;
const D INF = 1<<28,EPS = 1;

typedef complex<D> P;
#define X real()
#define Y imag()
istream& operator >> (istream& is,P& p){D x,y;is >> x >> y; p=P(x,y); return is;}

int sig(D a,D b=0){return a<b-EPS?-1:a>b+EPS?1:0;}
template<typename T> bool eq(const T& a,const T& b){return sig(abs(a-b))==0;}
bool compX (const P& a,const P& b){return !eq(a.X,b.X)?sig(a.X,b.X)<0:sig(a.Y,b.Y)<0;}
namespace std{
	bool operator <  (const P& a,const P& b){return compX(a,b);}
  	bool operator == (const P& a,const P& b){return eq(a,b);}
};
// a×b
D cross(const P& a,const P& b){return imag(conj(a)*b);}
// a・b
D dot(const P& a,const P& b) {return real(conj(a)*b);}
int ccw(const P& a,P b,P c){
    b -= a; c -= a;
    if (sig(cross(b,c)) > 0)   return +1;       // counter clockwise
    if (sig(cross(b,c)) < 0)   return -1;       // clockwise
    if (sig(dot(b,c)) < 0)     return +2;       // c--a--b on line
    if (sig(norm(b),norm(c))<0) return -2;       // a--b--c on line
    return 0; //a--c--b on line (c==b,c==a)
}
// //must template


namespace _convex_poly{
	typedef vector<P> Poly,ConvexPoly;
	
  	// 凸包
	//O(n logn)
	// verified by AOJLIB
    // http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1092743
	ConvexPoly convex_hull(Poly ps) {
		int n = ps.size(), k = 0;
		sort(ALL(ps));
		Poly ch(2*n);
		REP(i,n){ // lower-hull
			while (k > 1 && cross(ch[k-1]-ch[k-2],ps[i]-ch[k-1]) < 0) --k;
			ch[k++]=ps[i];
		}
		for(int i=n-2,t=k;i>=0;i--){// upper-hull
			while (k > t && cross(ch[k-1]-ch[k-2],ps[i]-ch[k-1]) < 0) --k;
			ch[k++]=ps[i];
		}
		ch.resize(k-1);
		return ch;
	}

	double dst(P a,P b){
		return sqrt((a.imag()-b.imag())*(a.imag()-b.imag())+(a.real()-b.real())*(a.real()-b.real()));
	}
	// 凸多角形の直径
    // O(n)
    // verified by AOJLIB
    // http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1092749
    double convex_diameter(const ConvexPoly &ps) {
        const int n = ps.size();
        int is=0;REP(i,n)if(ps[i].Y > ps[is].Y) is = i;
        int js=0;REP(j,n)if(ps[j].Y < ps[js].Y) js = j;
        double maxd = dst(ps[is],ps[js]);
        int i = is, maxi = is, j =js, maxj=js;
        do {
            if(cross(ps[(i+1)%n]-ps[i],ps[(j+1)%n]-ps[j]) >= 0) j = (j+1)%n;
            else i = (i+1)%n;
            if(dst(ps[i],ps[j]) > maxd) maxd = dst(ps[i],ps[j]);maxi = i; maxj = j;
        } while (i != is || j != js);
        return maxd;
        // farthest pair is (maxi, maxj).
    }
}
using namespace _convex_poly;

int MN=120050;
UnionFind uf(MN);
int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	cout <<fixed <<setprecision(20);

	int N;scanf("%d",&N);
	map<pair<int,int>,int> pmap;
	REP(i,N){
		int x,y;scanf("%d%d",&x,&y);
		pmap[make_pair(x,y)]=i;
	}

	vector<pair<int,int>> ds;
	for(int dx=-10;dx<=10;dx++)for(int dy=0;dy<=10;dy++)if(dx*dx+dy*dy<=100){
		ds.push_back(make_pair(dx,dy));
	}

	EACH(it,pmap)REP(j,ds.size()){
		pair<int,int> p(it->first.first+ds[j].first,it->first.second + ds[j].second);
		if(pmap.count(p))uf.unite(it->second,pmap[p]);
	}

	double Mv=1;
	if(N>0)Mv=2;
	vector<vector<P>> vs(N);EACH(it,pmap)vs[uf.par[it->second]].push_back(P(it->first.first,it->first.second));
	REP(i,vs.size())if(vs[i].size()>=2){
		vs[i]=convex_hull(vs[i]);
		Mv=max(Mv,convex_diameter(vs[i])+2);
	}

	cout << Mv <<endl;

 	return 0;
 }
0