結果

問題 No.96 圏外です。
ユーザー kroton
提出日時 2014-11-06 02:40:15
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 314 ms / 5,000 ms
コード長 3,826 bytes
コンパイル時間 968 ms
コンパイル使用メモリ 86,564 KB
実行使用メモリ 193,264 KB
最終ジャッジ日時 2024-12-24 07:39:05
合計ジャッジ時間 7,037 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <complex>
#include <queue>
#include <algorithm>
using namespace std;
typedef complex<double> P;
namespace std {
bool operator < (const P& a, const P& b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}
int ccw(P a, P b, P c) {
b -= a; c -= a;
if (cross(b, c) > 0) return +1; // counter clockwise
if (cross(b, c) < 0) return -1; // clockwise
if (dot(b, c) < 0) return +2; // c--a--b on line
if (norm(b) < norm(c)) return -2; // a--b--c on line
return 0;
}
vector<P> convex_hull(vector<P> ps) {
int n = (int)ps.size(), k = 0;
sort(ps.begin(), ps.end());
vector<P> ch(2*n);
for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
ch.resize(k-1);
return ch;
}
double farthest(const vector<P>& v) {
int n = (int)v.size();
int si = 0, sj = 0;
for(int t=0;t<n;t++){
if (v[t].imag() < v[si].imag())
si = t;
if (v[t].imag() > v[sj].imag())
sj = t;
}
double res = 0;
int i = si, j = sj;
do {
res = max(res, abs(v[i]-v[j]));
P di = v[(i+1)%n] - v[i];
P dj = v[(j+1)%n] - v[j];
if (cross(di, dj) >= 0)
j = (j+1)%n;
else
i = (i+1)%n;
} while(!(i == si && j == sj));
return res;
}
const int OFFSET = 10000;
const int B = 11;
int N;
int X[122222], Y[122222];
vector<int> bucket[2222][2222];
vector<int> graph[122222];
bool reachable(int i, int j){
int dx = X[i] - X[j];
int dy = Y[i] - Y[j];
return (dx * dx + dy * dy <= 100);
}
bool used[122222];
double solve(){
double res = 0;
for(int i=0;i<N;i++)if(!used[i]){
vector<P> ps;
ps.push_back(P(X[i], Y[i]));
queue<int> Q;
Q.push(i);
used[i] = true;
while(!Q.empty()){
int v = Q.front(); Q.pop();
for(int u : graph[v]){
if(used[u])continue;
used[u] = true;
Q.push(u);
ps.push_back(P(X[u], Y[u]));
}
}
if(ps.size() <= 1)continue;
if(ps.size() == 2){
res = max(res, abs(ps[0] - ps[1]));
continue;
}
vector<P> convex = convex_hull(ps);
res = max(res, farthest(convex));
}
return res + 2;
}
int main(){
cin >> N;
if(N == 0){
cout << 1 << endl;
return 0;
}
for(int i=0;i<N;i++){
cin >> X[i] >> Y[i];
X[i] += OFFSET;
Y[i] += OFFSET;
}
for(int i=0;i<N;i++){
int ix = X[i] / B;
int iy = Y[i] / B;
bucket[ix][iy].push_back(i);
}
for(int i=0;i<N;i++){
int ix = X[i] / B;
int iy = Y[i] / B;
for(int dx=-1;dx<=1;dx++)for(int dy=-1;dy<=1;dy++){
int nx = ix + dx;
int ny = iy + dy;
if(nx < 0 || ny < 0)continue;
for(int j : bucket[nx][ny]){
if(j != i && reachable(i, j)){
graph[i].push_back(j);
}
}
}
}
printf("%.10f\n", solve());
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0