106612024-04-07 19:21:25Valaki2Rajzcpp17Wrong answer 0/100345ms21948 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

struct point {
    int x, y;
    int id;
    point() : x(0), y(0), id(-1) {}
    point(int x_, int y_, int id_) :
        x(x_), y(y_), id(id_) {}
};

int sg(int x) {
    if(x < 0) {
        return -1;
    }
    if(x > 0) {
        return 1;
    }
    return 0;
}

int direction(point a, point b, point c) {
    return sg((c.y - a.y) * (b.x - a.x) - (b.y - a.y) * (c.x - a.x));
}

bool between(point a, point b, point c) {
    return c.x >= min(a.x, b.x) && c.x <= max(a.x, b.x) && c.y >= min(a.y, b.y) && c.y <= max(a.y, b.y);
}

bool on_segment(point a, point b, point c) {
    return direction(a, b, c) == 0 && between(a, b, c);
}

bool intersect(point a, point b, point c, point d) {
    return on_segment(a, b, c) || on_segment(a, b, d) || on_segment(c, d, a) || on_segment(c, d, b)
        || (direction(a, b, c) * direction(a, b, d) == -1 && direction(c, d, a) * direction(c, d, b) == -1);
}

const int maxn = 1000;
const int inf = 1e9 + 7;
const point far = point(1, -inf, -1);
const point origin = point(0, 0, -1);

int n;
point points[1 + maxn];
unsigned int dist[1 + maxn][1 + maxn];
bool intersects[1 + maxn][1 + maxn];
int vis[1 + maxn];
unsigned int len;
int cur_comp;

void dfs(int cur) {
    vis[cur] = cur_comp;
    for(int nei = 1; nei <= n; nei++) {
        if(nei == cur || vis[nei] || dist[cur][nei] > len || intersects[cur][nei]) {
            continue;
        }
        dfs(nei);
    }
}

bool good(unsigned int cur_len) {
    len = cur_len;
    cur_comp = 0;
    for(int i = 1; i <= n; i++) {
        vis[i] = false;
    }
    for(int i = 1; i <= n; i++) {
        if(!vis[i]) {
            cur_comp++;
            dfs(i);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(i != j && vis[i] == vis[j] && intersects[i][j]) {
                return true;
            }
        }
    }
    return false;
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> points[i].x >> points[i].y;
        points[i].id = i;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dist[i][j] = (points[i].x - points[j].x) * (points[i].x - points[j].x)
                + (points[i].y - points[j].y) * (points[i].y - points[j].y);
            intersects[i][j] = intersect(points[i], points[j], origin, far);
        }
    }
    unsigned int l = 0, r = 8e18 + 1;
    while(l < r - 1) {
        unsigned int mid = (l + r) / 2;
        if(good(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    if(r == 8e18 + 1) {
        cout << "-1\n";
    } else {
        cout << r << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2076 KiB
2Wrong answer3ms2396 KiB
subtask20/20
3Wrong answer3ms2352 KiB
4Accepted3ms2612 KiB
5Accepted3ms2728 KiB
6Accepted3ms2936 KiB
7Wrong answer3ms3016 KiB
8Wrong answer3ms3240 KiB
9Accepted3ms3256 KiB
10Wrong answer3ms3204 KiB
11Accepted3ms3412 KiB
12Accepted3ms3628 KiB
subtask30/20
13Wrong answer3ms2352 KiB
14Accepted3ms2612 KiB
15Accepted3ms2728 KiB
16Accepted3ms2936 KiB
17Wrong answer3ms3016 KiB
18Wrong answer3ms3240 KiB
19Accepted3ms3256 KiB
20Wrong answer3ms3204 KiB
21Accepted3ms3412 KiB
22Accepted3ms3628 KiB
23Wrong answer3ms3804 KiB
24Accepted3ms3892 KiB
25Wrong answer3ms3804 KiB
26Wrong answer3ms3804 KiB
27Accepted3ms4076 KiB
28Wrong answer3ms3924 KiB
29Accepted3ms3812 KiB
30Accepted3ms3820 KiB
31Accepted3ms3612 KiB
subtask40/20
32Wrong answer3ms2352 KiB
33Accepted3ms2612 KiB
34Accepted3ms2728 KiB
35Accepted3ms2936 KiB
36Wrong answer3ms3016 KiB
37Wrong answer3ms3240 KiB
38Accepted3ms3256 KiB
39Wrong answer3ms3204 KiB
40Accepted3ms3412 KiB
41Accepted3ms3628 KiB
42Wrong answer3ms3804 KiB
43Accepted3ms3892 KiB
44Wrong answer3ms3804 KiB
45Wrong answer3ms3804 KiB
46Accepted3ms4076 KiB
47Wrong answer3ms3924 KiB
48Accepted3ms3812 KiB
49Accepted3ms3820 KiB
50Accepted3ms3612 KiB
51Wrong answer4ms4808 KiB
52Wrong answer4ms5068 KiB
53Wrong answer4ms4944 KiB
54Wrong answer4ms4892 KiB
55Wrong answer4ms4880 KiB
56Wrong answer6ms4992 KiB
57Wrong answer6ms5008 KiB
58Wrong answer6ms5084 KiB
59Wrong answer6ms5084 KiB
60Wrong answer6ms5212 KiB
61Accepted6ms5212 KiB
62Wrong answer6ms5292 KiB
63Wrong answer6ms5284 KiB
64Wrong answer6ms5412 KiB
65Wrong answer6ms5408 KiB
66Accepted4ms5304 KiB
67Accepted6ms5288 KiB
68Accepted6ms5404 KiB
69Accepted6ms5404 KiB
70Accepted6ms5408 KiB
subtask50/40
71Wrong answer3ms2352 KiB
72Accepted3ms2612 KiB
73Accepted3ms2728 KiB
74Accepted3ms2936 KiB
75Wrong answer3ms3016 KiB
76Wrong answer3ms3240 KiB
77Accepted3ms3256 KiB
78Wrong answer3ms3204 KiB
79Accepted3ms3412 KiB
80Accepted3ms3628 KiB
81Wrong answer3ms3804 KiB
82Accepted3ms3892 KiB
83Wrong answer3ms3804 KiB
84Wrong answer3ms3804 KiB
85Accepted3ms4076 KiB
86Wrong answer3ms3924 KiB
87Accepted3ms3812 KiB
88Accepted3ms3820 KiB
89Accepted3ms3612 KiB
90Wrong answer4ms4808 KiB
91Wrong answer4ms5068 KiB
92Wrong answer4ms4944 KiB
93Wrong answer4ms4892 KiB
94Wrong answer4ms4880 KiB
95Wrong answer6ms4992 KiB
96Wrong answer6ms5008 KiB
97Wrong answer6ms5084 KiB
98Wrong answer6ms5084 KiB
99Wrong answer6ms5212 KiB
100Accepted6ms5212 KiB
101Wrong answer6ms5292 KiB
102Wrong answer6ms5284 KiB
103Wrong answer6ms5412 KiB
104Wrong answer6ms5408 KiB
105Accepted4ms5304 KiB
106Accepted6ms5288 KiB
107Accepted6ms5404 KiB
108Accepted6ms5404 KiB
109Accepted6ms5408 KiB
110Wrong answer173ms21748 KiB
111Wrong answer164ms21752 KiB
112Wrong answer163ms21784 KiB
113Wrong answer168ms21896 KiB
114Wrong answer177ms21796 KiB
115Wrong answer172ms21784 KiB
116Wrong answer261ms21808 KiB
117Wrong answer284ms21848 KiB
118Wrong answer345ms21816 KiB
119Wrong answer287ms21948 KiB
120Wrong answer293ms21888 KiB
121Wrong answer282ms21776 KiB
122Wrong answer250ms21776 KiB
123Wrong answer252ms21748 KiB
124Wrong answer247ms21748 KiB
125Wrong answer240ms21784 KiB
126Wrong answer303ms21752 KiB
127Accepted256ms21748 KiB
128Accepted321ms21736 KiB
129Accepted204ms21752 KiB
130Accepted252ms21744 KiB
131Accepted263ms21788 KiB
132Accepted266ms21788 KiB