結果
問題 | No.96 圏外です。 |
ユーザー | 沙耶花 |
提出日時 | 2021-10-25 23:32:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,113 bytes |
コンパイル時間 | 5,556 ms |
コンパイル使用メモリ | 288,944 KB |
実行使用メモリ | 39,148 KB |
最終ジャッジ日時 | 2024-10-03 22:36:53 |
合計ジャッジ時間 | 17,524 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 14 ms
6,816 KB |
testcase_05 | AC | 23 ms
6,816 KB |
testcase_06 | AC | 36 ms
6,820 KB |
testcase_07 | AC | 56 ms
6,820 KB |
testcase_08 | AC | 79 ms
6,816 KB |
testcase_09 | AC | 112 ms
6,820 KB |
testcase_10 | AC | 163 ms
6,820 KB |
testcase_11 | AC | 198 ms
6,820 KB |
testcase_12 | AC | 249 ms
6,816 KB |
testcase_13 | AC | 385 ms
6,816 KB |
testcase_14 | AC | 419 ms
7,936 KB |
testcase_15 | WA | - |
testcase_16 | AC | 648 ms
9,728 KB |
testcase_17 | AC | 708 ms
11,648 KB |
testcase_18 | WA | - |
testcase_19 | AC | 815 ms
11,008 KB |
testcase_20 | AC | 994 ms
18,448 KB |
testcase_21 | AC | 794 ms
28,356 KB |
testcase_22 | AC | 1,067 ms
37,580 KB |
testcase_23 | AC | 1,026 ms
39,148 KB |
testcase_24 | AC | 2 ms
6,820 KB |
testcase_25 | AC | 484 ms
9,216 KB |
testcase_26 | AC | 642 ms
10,992 KB |
testcase_27 | AC | 547 ms
9,856 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 100000000000 const long double eps = 1e-10; template <typename T> struct vector_2d{ T x,y,rad,dir; vector_2d(T a=0.0,T b=0.0){ x = a; y = b; fix_rd(); } void update_x(T a,T b){ x = a*x + b; fix_rd(); } void update_x(T a){ update_x(0.0,a); } void update_y(T a,T b){ y = a*y + b; fix_rd(); } void update_y(T a){ update_y(0.0,a); } void update_rad(T a,T b){ rad = a*rad + b; fix_xy(); } void update_rad(T a){ update_rad(0.0,a); } void update_dir(T a,T b){ dir = a*dir + b; fix_xy(); } void update_dir(T a){ update_dir(0.0,a); } void fix_xy(){ x = rad * cos(dir); y = rad * sin(dir); fix_rd(); } void fix_rd(){ rad = hypot(x,y); if(rad==0.0)dir=0.0; else dir = atan2(y,x); fix_zero(); } void fix_zero(){ if(abs(x)<eps)x = 0.0; if(abs(y)<eps)y = 0.0; if(abs(rad)<eps)rad = 0.0; if(abs(dir)<eps)dir = 0.0; } void normalize(){ T s = size(); update_x(1.0/s,0.0); update_y(1.0/s,0.0); } T get_dis(vector_2d<T> V){ return hypot(x-V.x,y-V.y); } T size(){ return get_dis(vector_2d<T>()); } T angle_difference(vector_2d<T> V){ long double ret = dir - V.dir; if(ret<-acos(-1.0))ret = acos(-1.0)*2.0+ret; if(ret>acos(-1.0))ret=-acos(-1.0)*2.0+ret; return ret; } //中点 vector_2d get_midpoint(vector_2d<T> V){ V.update_x(0.5,x/2.0); V.update_y(0.5,y/2.0); return V; } T get_inner_product(vector_2d<T> V){ return x*V.x+y*V.y; } T get_cross_product(vector_2d<T> V){ return x*V.y-y*V.x; } vector_2d &operator+=(const vector_2d<T> &another){ update_x(1,another.x); update_y(1,another.y); return (*this); } vector_2d &operator-=(const vector_2d<T> &another){ update_x(1,-another.x); update_y(1,-another.y); return (*this); } vector_2d operator+(const vector_2d<T> &another)const{ return (vector_2d(*this)+=another); } vector_2d operator-(const vector_2d<T> &another)const{ return (vector_2d(*this)-=another); } void show(){ cout<<x<<','<<y<<endl; } }; //a+tx template <typename T> struct line{ vector_2d<T> a,t; line(vector_2d<T> V1,vector_2d<T> V2){ a=V1; t=V2-V1; } T get_signed_dis(vector_2d<T> V){ vector_2d<long double> PA = a-V; return PA.get_cross_product(t)/t.size(); } T get_dis(vector_2d<T> V){ return abs(get_signed_dis(V)); } vector_2d<T> get_projection(vector_2d<T> P){ T r = t.get_inner_product(P-a)/t.size(); vector_2d<T> temp = t; temp.update_rad(0.0,r); return a+temp; } vector_2d<T> get_cross_point(line<T> L){ vector_2d<T> ret(1e20,1e20); if(abs(t.get_cross_product(L.t))<eps)return ret; T d0 = L.get_signed_dis(a); T d1 = L.get_signed_dis(a+t); vector_2d<T> temp = t; temp.x *= d0/(d1-d0); temp.y *= d0/(d1-d0); ret = a - temp; return ret; } }; template <typename T> struct segment{ vector_2d<T> V1,V2; segment(vector_2d<T> a=vector_2d<T>(),vector_2d<T> b=vector_2d<T>()){ V1=a; V2=b; } T get_dis(vector_2d<T> P){ T ret = 1e20; line<T> L(V1,V2); vector_2d<T> Q = L.get_projection(P); if(Q.x+eps>min(V1.x,V2.x)&&Q.y+eps>min(V1.y,V2.y) &&Q.x<max(V1.x,V2.x)+eps&&Q.y<max(V1.y,V2.y)+eps)ret = min(ret,Q.get_dis(P)); else{ ret = min(ret,P.get_dis(V1)); ret = min(ret,P.get_dis(V2)); } return ret; } T get_dis(segment<T> l){ if(get_cross_point(l).x<1e20)return 0.0; return min({get_dis(l.V1),get_dis(l.V2),l.get_dis(V1),l.get_dis(V2)}); } vector_2d<T> get_cross_point(segment<T> l){ line<T> L1(V1,V2),L2(l.V1,l.V2); vector_2d<T> P = L1.get_cross_point(L2); if(get_dis(P)<eps&&l.get_dis(P)<eps)return P; return vector_2d<T> (1e20,1e20); } }; template <typename T> struct triangle{ vector_2d<T> V[3]; triangle(vector_2d<T> V1,vector_2d<T> V2,vector_2d<T> V3){ V[0] = V1; V[1] = V2; V[2] = V3; } vector_2d<T> get_circumcenter(){ line<T> L1(V[0],V[1]); vector_2d<T> M1 = V[0].get_midpoint(V[1]); L1 = line<T>(M1,L1.b,L1.a); line<T> L2(V[1],V[2]); vector_2d<T> M2 = V[1].get_midpoint(V[2]); L2 = line<T>(M2,L2.b,L2.a); return L1.get_cross_point(L2); } T get_signed_area(){ return ((V[1].x-V[0].x)*(V[2].y-V[0].y) - (V[2].x-V[0].x)*(V[1].y-V[0].y))/2.0; } T get_area(){ return abs(get_signed_area()); } bool is_inside(vector_2d<T> P){ T S = triangle<T>(V[0],V[1],P).get_area() + triangle<T>(V[1],V[2],P).get_area() + triangle<T>(V[2],V[0],P).get_area(); return abs(S - get_area())<eps; } bool is_clockwise(){ vector_2d<T> X = V[1]-V[0],Y = V[2]-V[1]; return X.x*Y.y-X.y*Y.x < 0.0; } }; template <typename T> struct polygon{ vector<vector_2d<T>> V; polygon(vector<vector_2d<T>> v){ V = v; } bool is_convex(){ bool f = false; for(int i=0;i<V.size();i++){ triangle<T> tri(V[i],V[(i+1)%V.size()],V[(i+2)%V.size()]); if(i==0)f = tri.is_clockwise(); else{ if(tri.is_clockwise()!=f)return false; } } return true; } T get_signed_area(){ T ret = 0.0; for(int i=1;i<V.size()-1;i++){ triangle<T> tri(V[0],V[i],V[i+1]); ret += tri.get_signed_area(); } return ret; } T get_area(){ return abs(get_signed_area()); } T get_diameter(){ vector<T> dis(V.size()); int now = 0; for(int i=0;i<V.size();i++){ while(true){ int next = (now+1)%V.size(); if(V[i].get_dis(V[now])<V[i].get_dis(V[next])+eps){ now = next; continue; } else{ break; } } dis[i] = V[i].get_dis(V[now]); } T ret = 0.0; for(int i=0;i<V.size();i++)ret = max(ret,dis[i]); return ret; } bool is_on_side(vector_2d<T> P){ for(int i=0;i<V.size();i++){ segment<T> l(V[i],V[(i+1)%V.size()]); if(l.get_dis(P)<eps)return true; } return false; } bool is_inside(vector_2d<T> P){ if(is_on_side(P))return true; long double R = 0.0; for(int i=0;i<V.size();i++){ vector_2d<T> p1(V[i]-P),p2(V[(i+1)%V.size()]-P); R += p1.angle_difference(p2); } return abs(R)>=eps; } }; template <typename T> struct circle{ vector_2d<T> C; T R; circle(vector_2d<T> c=vector_2d<T>(),T r=0.0){ C = c; R = r; } vector<vector_2d<T>> get_cross_point(circle<T> C2){ vector<vector_2d<T>> ret; T d = C.get_dis(C2.C); if(d>R+C2.R+eps)return ret; if(d+eps<abs(R-C2.R))return ret; T cosine = (pow(R,2.0)+pow(d,2.0)-pow(C2.R,2.0))/(2.0*R*d); T Rc = R*cosine; T Rs = sqrt(pow(R,2.0)-pow(Rc,2.0)); vector_2d<T> e1 = (C2.C-C); e1.update_rad(1.0/d,0.0); vector_2d<T> e2 = e1; e2.update_dir(1.0,acos(-1.0)/2.0); e1.update_rad(Rc,0.0); e2.update_rad(Rs,0.0); ret.push_back(C + e1+e2); e2.update_dir(1.0,-acos(-1.0)); ret.push_back(C+e1+e2); return ret; } }; vector<int> get_CH(vector<vector_2d<long double>> &v){ vector<pair<vector_2d<long double>,int>> V(v.size()); for(int i=0;i<v.size();i++){ V[i].first=v[i]; V[i].second=i; } sort(V.begin(),V.end(),[](auto &a,auto &b){ if(abs(a.first.y-b.first.y)>eps)return a.first.y<b.first.y; return a.first.x<b.first.x; }); vector<int> ret; for(int i=0;i<V.size();i++){ if(ret.size()<2){ ret.push_back(i); } else{ vector_2d<long double> v1 = V[ret[ret.size()-2]].first,v2 = V[ret[ret.size()-1]].first,v3 = V[i].first; v3 -= v2; v2 -= v1; if(v2.get_cross_product(v3)>-eps){ ret.push_back(i); } else{ ret.pop_back(); i--; continue; } } } for(int i=(int)V.size()-2;i>=0;i--){ if(ret.size()<2){ ret.push_back(i); } else{ vector_2d<long double> v1 = V[ret[ret.size()-2]].first,v2 = V[ret[ret.size()-1]].first,v3 = V[i].first; v3 -= v2; v2 -= v1; if(v2.get_cross_product(v3)>-eps){ ret.push_back(i); } else{ ret.pop_back(); i++; continue; } } } ret.pop_back(); for(int i=0;i<ret.size();i++)ret[i] = V[ret[i]].second; set<int> S; { vector<int> ret2; for(int i=0;i<ret.size();i++){ if(S.count(ret[i]))continue; ret2.push_back(ret[i]); S.insert(ret[i]); } ret = ret2; } return ret; } int main(){ int N; cin>>N; vector<pair<int,int>> xy(N); rep(i,N){ cin>>xy[i].first>>xy[i].second; } sort(xy.begin(),xy.end()); dsu D(N); rep(i,N){ int x = xy[i].first,y = xy[i].second; rep(j,11){ for(int k=-10;k<=10;k++){ if(j*j + k*k <= 100){ int d = distance(xy.begin(),lower_bound(xy.begin(),xy.end(),make_pair(x+j,y+k))); if(d!=N && xy[d]==make_pair(x+j,y+k))D.merge(d,i); } } } } long double ans = 1.0; auto g = D.groups(); rep(i,g.size()){ if(g[i].size()==1){ ans = max(ans,(long double)2.0); continue; } vector<vector_2d<long double>> temp; rep(j,g[i].size()){ temp.push_back(vector_2d<long double>(xy[g[i][j]].first,xy[g[i][j]].second)); } auto ret = get_CH(temp); vector<vector_2d<long double>> temp2; rep(j,ret.size()){ temp2.push_back(temp[ret[j]]); } polygon<long double> P(temp); ans = max(ans,P.get_diameter()+2.0); } cout<<fixed<<setprecision(10)<<ans<<endl; return 0; }