結果

問題 No.96 圏外です。
ユーザー krotonkroton
提出日時 2014-11-06 02:40:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 278 ms / 5,000 ms
コード長 3,826 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 86,040 KB
実行使用メモリ 193,304 KB
最終ジャッジ日時 2023-08-25 21:20:55
合計ジャッジ時間 6,252 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
122,324 KB
testcase_01 AC 46 ms
122,292 KB
testcase_02 AC 46 ms
122,360 KB
testcase_03 AC 45 ms
122,132 KB
testcase_04 AC 48 ms
122,288 KB
testcase_05 AC 50 ms
122,256 KB
testcase_06 AC 52 ms
122,360 KB
testcase_07 AC 55 ms
122,652 KB
testcase_08 AC 59 ms
122,904 KB
testcase_09 AC 63 ms
123,108 KB
testcase_10 AC 69 ms
123,528 KB
testcase_11 AC 77 ms
123,604 KB
testcase_12 AC 85 ms
123,984 KB
testcase_13 AC 104 ms
125,084 KB
testcase_14 AC 113 ms
125,516 KB
testcase_15 AC 142 ms
126,832 KB
testcase_16 AC 150 ms
127,012 KB
testcase_17 AC 162 ms
127,100 KB
testcase_18 AC 184 ms
128,384 KB
testcase_19 AC 175 ms
128,360 KB
testcase_20 AC 184 ms
137,084 KB
testcase_21 AC 212 ms
135,280 KB
testcase_22 AC 278 ms
193,304 KB
testcase_23 AC 275 ms
193,296 KB
testcase_24 AC 46 ms
122,056 KB
testcase_25 AC 121 ms
125,612 KB
testcase_26 AC 148 ms
126,540 KB
testcase_27 AC 134 ms
126,000 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0