53972023-05-10 18:27:05mraronRajzcpp17Time limit exceeded 60/1001.082s8856 KiB
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

struct point{
    long long x, y;
    point(long long x = 0, long long y = 0) : x(x), y(y) {}
    point operator-() const { return point(-x, -y); }
    point operator+(point p) const { return point(x + p.x, y + p.y); }
    point operator-(point p) const { return (*this) + (-p); }
    long long len() const { return x*x + y*y; }
};

inline long long cross(point a, point b) { return a.x * b.y - b.x * a.y; }

inline int sgn(long long x) { return (x > 0) - (x < 0); }

inline int dir(point a, point b, point c) { return sgn(cross(b-a, c-a)); }

inline bool contains(point a, point b, point c, point d){
    int d1 = dir(a, b, d);
    int d2 = dir(b, c, d);
    int d3 = dir(c, a, d);
    return d1 == d2 && d2 == d3;
}

vector<vector<int>> g;
vector<bool> vis, done;
vector<point> v;

void add_edge(int x, int y){
    if(dir(v[x], v[y], point(0, 0)) > 0) g[x].push_back(y);
    else g[y].push_back(x);
}

bool dfs(int x){
    vis[x] = true;
    for(int y : g[x]){
        if((vis[y] && !done[y]) || (!vis[y] && dfs(y))) return true;
    }
    done[x] = true;
    return false;
}

const long long INF = 8e18 + 1;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;

    v.resize(n);
    for(auto &[x, y] : v) cin>>x>>y;

    long long lo = 0, hi = INF;
    while(lo + 1 < hi){
        long long mid = lo + (hi - lo) / 2;
        deque<pair<int, int>> q;
        vector<vector<bool>> used(n, vector<bool>(n));
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if((v[i]-v[j]).len() <= mid){
                    q.emplace_back(i, j);
                    used[i][j] = used[j][i] = true;
                }
            }
        }
        g.assign(n, vector<int>());
        while (!q.empty()) {
            int x = q.front().first, y = q.front().second;
            q.pop_front();
            add_edge(x, y);
            for(int i = 0; i < n; i++){
                if(i == x || i == y || contains(v[x], v[y], v[i], point(0, 0))) continue;
                if(used[x][i] && !used[y][i]) {
                    q.emplace_back(y, i);
                    used[y][i] = used[i][y] = true;
                }
                if(!used[x][i] && used[y][i]) {
                    q.emplace_back(x, i);
                    used[x][i] = used[i][x] = true;
                }
            }
        }
        vis.assign(n, false);
        done.assign(n, false);
        bool ok = false;
        for(int i = 0; i < n; i++){
            if(!vis[i]){
                ok = ok || dfs(i);
            }
        }
        if(ok) hi = mid;
        else lo = mid;
    }

    if(hi == INF) cout<<-1<<'\n';
    else cout<<hi<<'\n';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2032 KiB
subtask220/20
3Accepted3ms2032 KiB
4Accepted3ms2260 KiB
5Accepted3ms2328 KiB
6Accepted3ms2460 KiB
7Accepted3ms2672 KiB
8Accepted3ms2756 KiB
9Accepted3ms2980 KiB
10Accepted3ms2988 KiB
11Accepted3ms2968 KiB
12Accepted3ms2964 KiB
13Accepted3ms3096 KiB
subtask320/20
14Accepted3ms3096 KiB
15Accepted3ms2260 KiB
16Accepted3ms2328 KiB
17Accepted3ms2460 KiB
18Accepted3ms2672 KiB
19Accepted3ms2756 KiB
20Accepted3ms2980 KiB
21Accepted3ms2988 KiB
22Accepted3ms2968 KiB
23Accepted3ms2964 KiB
24Accepted3ms3096 KiB
25Accepted6ms3308 KiB
26Accepted6ms3412 KiB
27Accepted6ms3408 KiB
28Accepted4ms3488 KiB
29Accepted6ms3488 KiB
30Accepted6ms3620 KiB
31Accepted6ms3712 KiB
32Accepted6ms3740 KiB
33Accepted3ms3972 KiB
subtask420/20
34Accepted3ms3972 KiB
35Accepted3ms2260 KiB
36Accepted3ms2328 KiB
37Accepted3ms2460 KiB
38Accepted3ms2672 KiB
39Accepted3ms2756 KiB
40Accepted3ms2980 KiB
41Accepted3ms2988 KiB
42Accepted3ms2968 KiB
43Accepted3ms2964 KiB
44Accepted3ms3096 KiB
45Accepted6ms3308 KiB
46Accepted6ms3412 KiB
47Accepted6ms3408 KiB
48Accepted4ms3488 KiB
49Accepted6ms3488 KiB
50Accepted6ms3620 KiB
51Accepted6ms3712 KiB
52Accepted6ms3740 KiB
53Accepted3ms3972 KiB
54Accepted565ms4136 KiB
55Accepted541ms4136 KiB
56Accepted559ms4152 KiB
57Accepted555ms4148 KiB
58Accepted575ms4124 KiB
59Accepted504ms4124 KiB
60Accepted411ms4128 KiB
61Accepted391ms4276 KiB
62Accepted486ms4384 KiB
63Accepted451ms4340 KiB
64Accepted432ms4336 KiB
65Accepted453ms4392 KiB
66Accepted432ms4464 KiB
67Accepted456ms4624 KiB
68Accepted465ms4576 KiB
69Accepted493ms4724 KiB
70Accepted477ms4616 KiB
71Accepted476ms4848 KiB
72Accepted481ms4932 KiB
73Accepted483ms4840 KiB
subtask50/40
74Accepted483ms4840 KiB
75Accepted3ms2260 KiB
76Accepted3ms2328 KiB
77Accepted3ms2460 KiB
78Accepted3ms2672 KiB
79Accepted3ms2756 KiB
80Accepted3ms2980 KiB
81Accepted3ms2988 KiB
82Accepted3ms2968 KiB
83Accepted3ms2964 KiB
84Accepted3ms3096 KiB
85Accepted6ms3308 KiB
86Accepted6ms3412 KiB
87Accepted6ms3408 KiB
88Accepted4ms3488 KiB
89Accepted6ms3488 KiB
90Accepted6ms3620 KiB
91Accepted6ms3712 KiB
92Accepted6ms3740 KiB
93Accepted3ms3972 KiB
94Accepted565ms4136 KiB
95Accepted541ms4136 KiB
96Accepted559ms4152 KiB
97Accepted555ms4148 KiB
98Accepted575ms4124 KiB
99Accepted504ms4124 KiB
100Accepted411ms4128 KiB
101Accepted391ms4276 KiB
102Accepted486ms4384 KiB
103Accepted451ms4340 KiB
104Accepted432ms4336 KiB
105Accepted453ms4392 KiB
106Accepted432ms4464 KiB
107Accepted456ms4624 KiB
108Accepted465ms4576 KiB
109Accepted493ms4724 KiB
110Accepted477ms4616 KiB
111Accepted476ms4848 KiB
112Accepted481ms4932 KiB
113Accepted483ms4840 KiB
114Time limit exceeded1.074s8264 KiB
115Time limit exceeded1.054s8440 KiB
116Time limit exceeded1.024s8428 KiB
117Time limit exceeded1.049s8476 KiB
118Time limit exceeded1.082s8324 KiB
119Time limit exceeded1.065s8364 KiB
120Time limit exceeded1.07s8396 KiB
121Time limit exceeded1.065s8348 KiB
122Time limit exceeded1.052s8412 KiB
123Time limit exceeded1.054s8436 KiB
124Time limit exceeded1.075s8496 KiB
125Time limit exceeded1.057s8480 KiB
126Time limit exceeded1.062s8480 KiB
127Time limit exceeded1.057s8492 KiB
128Time limit exceeded1.057s8532 KiB
129Time limit exceeded1.082s8412 KiB
130Time limit exceeded1.057s8388 KiB
131Time limit exceeded1.065s8616 KiB
132Time limit exceeded1.041s8392 KiB
133Time limit exceeded1.049s8424 KiB
134Time limit exceeded1.07s8708 KiB
135Time limit exceeded1.07s8720 KiB
136Time limit exceeded1.054s8856 KiB