結果
| 問題 |
No.96 圏外です。
|
| コンテスト | |
| ユーザー |
shimomire
|
| 提出日時 | 2014-12-07 23:54:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 5,161 bytes |
| コンパイル時間 | 1,669 ms |
| コンパイル使用メモリ | 140,456 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-06-11 17:49:42 |
| 合計ジャッジ時間 | 8,857 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 1 -- * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:151:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
151 | int N;scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:154:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
154 | int x,y;scanf("%d%d",&x,&y);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#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=-10;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;
}
shimomire