#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];
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 || intersect(points[cur], points[nei], origin, far)) {
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] && intersect(points[i], points[j], origin, far)) {
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);
}
}
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();
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2064 KiB | ||||
2 | Wrong answer | 3ms | 2400 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Wrong answer | 3ms | 2616 KiB | ||||
4 | Accepted | 3ms | 2464 KiB | ||||
5 | Accepted | 3ms | 2744 KiB | ||||
6 | Accepted | 3ms | 2940 KiB | ||||
7 | Wrong answer | 3ms | 3152 KiB | ||||
8 | Wrong answer | 3ms | 3180 KiB | ||||
9 | Accepted | 3ms | 3372 KiB | ||||
10 | Wrong answer | 3ms | 3784 KiB | ||||
11 | Accepted | 3ms | 3592 KiB | ||||
12 | Accepted | 3ms | 3908 KiB | ||||
subtask3 | 0/20 | ||||||
13 | Wrong answer | 3ms | 2616 KiB | ||||
14 | Accepted | 3ms | 2464 KiB | ||||
15 | Accepted | 3ms | 2744 KiB | ||||
16 | Accepted | 3ms | 2940 KiB | ||||
17 | Wrong answer | 3ms | 3152 KiB | ||||
18 | Wrong answer | 3ms | 3180 KiB | ||||
19 | Accepted | 3ms | 3372 KiB | ||||
20 | Wrong answer | 3ms | 3784 KiB | ||||
21 | Accepted | 3ms | 3592 KiB | ||||
22 | Accepted | 3ms | 3908 KiB | ||||
23 | Wrong answer | 3ms | 4240 KiB | ||||
24 | Accepted | 3ms | 4384 KiB | ||||
25 | Wrong answer | 3ms | 4392 KiB | ||||
26 | Wrong answer | 3ms | 4328 KiB | ||||
27 | Accepted | 3ms | 4444 KiB | ||||
28 | Wrong answer | 3ms | 4336 KiB | ||||
29 | Accepted | 4ms | 4452 KiB | ||||
30 | Accepted | 4ms | 4432 KiB | ||||
31 | Accepted | 3ms | 4388 KiB | ||||
subtask4 | 0/20 | ||||||
32 | Wrong answer | 3ms | 2616 KiB | ||||
33 | Accepted | 3ms | 2464 KiB | ||||
34 | Accepted | 3ms | 2744 KiB | ||||
35 | Accepted | 3ms | 2940 KiB | ||||
36 | Wrong answer | 3ms | 3152 KiB | ||||
37 | Wrong answer | 3ms | 3180 KiB | ||||
38 | Accepted | 3ms | 3372 KiB | ||||
39 | Wrong answer | 3ms | 3784 KiB | ||||
40 | Accepted | 3ms | 3592 KiB | ||||
41 | Accepted | 3ms | 3908 KiB | ||||
42 | Wrong answer | 3ms | 4240 KiB | ||||
43 | Accepted | 3ms | 4384 KiB | ||||
44 | Wrong answer | 3ms | 4392 KiB | ||||
45 | Wrong answer | 3ms | 4328 KiB | ||||
46 | Accepted | 3ms | 4444 KiB | ||||
47 | Wrong answer | 3ms | 4336 KiB | ||||
48 | Accepted | 4ms | 4452 KiB | ||||
49 | Accepted | 4ms | 4432 KiB | ||||
50 | Accepted | 3ms | 4388 KiB | ||||
51 | Wrong answer | 4ms | 5384 KiB | ||||
52 | Wrong answer | 4ms | 5592 KiB | ||||
53 | Wrong answer | 4ms | 5684 KiB | ||||
54 | Wrong answer | 4ms | 5820 KiB | ||||
55 | Wrong answer | 4ms | 6036 KiB | ||||
56 | Wrong answer | 8ms | 6120 KiB | ||||
57 | Wrong answer | 7ms | 6120 KiB | ||||
58 | Wrong answer | 9ms | 6076 KiB | ||||
59 | Wrong answer | 8ms | 6132 KiB | ||||
60 | Wrong answer | 8ms | 6348 KiB | ||||
61 | Accepted | 7ms | 6328 KiB | ||||
62 | Wrong answer | 7ms | 6480 KiB | ||||
63 | Wrong answer | 6ms | 6536 KiB | ||||
64 | Wrong answer | 7ms | 6436 KiB | ||||
65 | Wrong answer | 7ms | 6440 KiB | ||||
66 | Accepted | 13ms | 6532 KiB | ||||
67 | Accepted | 25ms | 6440 KiB | ||||
68 | Accepted | 28ms | 6432 KiB | ||||
69 | Accepted | 28ms | 6360 KiB | ||||
70 | Accepted | 26ms | 6440 KiB | ||||
subtask5 | 0/40 | ||||||
71 | Wrong answer | 3ms | 2616 KiB | ||||
72 | Accepted | 3ms | 2464 KiB | ||||
73 | Accepted | 3ms | 2744 KiB | ||||
74 | Accepted | 3ms | 2940 KiB | ||||
75 | Wrong answer | 3ms | 3152 KiB | ||||
76 | Wrong answer | 3ms | 3180 KiB | ||||
77 | Accepted | 3ms | 3372 KiB | ||||
78 | Wrong answer | 3ms | 3784 KiB | ||||
79 | Accepted | 3ms | 3592 KiB | ||||
80 | Accepted | 3ms | 3908 KiB | ||||
81 | Wrong answer | 3ms | 4240 KiB | ||||
82 | Accepted | 3ms | 4384 KiB | ||||
83 | Wrong answer | 3ms | 4392 KiB | ||||
84 | Wrong answer | 3ms | 4328 KiB | ||||
85 | Accepted | 3ms | 4444 KiB | ||||
86 | Wrong answer | 3ms | 4336 KiB | ||||
87 | Accepted | 4ms | 4452 KiB | ||||
88 | Accepted | 4ms | 4432 KiB | ||||
89 | Accepted | 3ms | 4388 KiB | ||||
90 | Wrong answer | 4ms | 5384 KiB | ||||
91 | Wrong answer | 4ms | 5592 KiB | ||||
92 | Wrong answer | 4ms | 5684 KiB | ||||
93 | Wrong answer | 4ms | 5820 KiB | ||||
94 | Wrong answer | 4ms | 6036 KiB | ||||
95 | Wrong answer | 8ms | 6120 KiB | ||||
96 | Wrong answer | 7ms | 6120 KiB | ||||
97 | Wrong answer | 9ms | 6076 KiB | ||||
98 | Wrong answer | 8ms | 6132 KiB | ||||
99 | Wrong answer | 8ms | 6348 KiB | ||||
100 | Accepted | 7ms | 6328 KiB | ||||
101 | Wrong answer | 7ms | 6480 KiB | ||||
102 | Wrong answer | 6ms | 6536 KiB | ||||
103 | Wrong answer | 7ms | 6436 KiB | ||||
104 | Wrong answer | 7ms | 6440 KiB | ||||
105 | Accepted | 13ms | 6532 KiB | ||||
106 | Accepted | 25ms | 6440 KiB | ||||
107 | Accepted | 28ms | 6432 KiB | ||||
108 | Accepted | 28ms | 6360 KiB | ||||
109 | Accepted | 26ms | 6440 KiB | ||||
110 | Wrong answer | 148ms | 21192 KiB | ||||
111 | Wrong answer | 130ms | 21436 KiB | ||||
112 | Wrong answer | 118ms | 21316 KiB | ||||
113 | Wrong answer | 130ms | 21336 KiB | ||||
114 | Wrong answer | 187ms | 21348 KiB | ||||
115 | Wrong answer | 135ms | 21384 KiB | ||||
116 | Wrong answer | 308ms | 21408 KiB | ||||
117 | Wrong answer | 351ms | 21508 KiB | ||||
118 | Wrong answer | 400ms | 21668 KiB | ||||
119 | Wrong answer | 360ms | 21700 KiB | ||||
120 | Wrong answer | 372ms | 21800 KiB | ||||
121 | Wrong answer | 351ms | 21840 KiB | ||||
122 | Wrong answer | 286ms | 21856 KiB | ||||
123 | Wrong answer | 256ms | 21760 KiB | ||||
124 | Wrong answer | 259ms | 21772 KiB | ||||
125 | Wrong answer | 225ms | 21716 KiB | ||||
126 | Time limit exceeded | 1.067s | 21884 KiB | ||||
127 | Accepted | 971ms | 21784 KiB | ||||
128 | Time limit exceeded | 1.062s | 13088 KiB | ||||
129 | Time limit exceeded | 1.05s | 21844 KiB | ||||
130 | Time limit exceeded | 1.059s | 13068 KiB | ||||
131 | Time limit exceeded | 1.062s | 13068 KiB | ||||
132 | Time limit exceeded | 1.078s | 13184 KiB |