106582024-04-07 19:06:52Valaki2Rajzcpp17Wrong answer 0/1001.078s21884 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];
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();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2064 KiB
2Wrong answer3ms2400 KiB
subtask20/20
3Wrong answer3ms2616 KiB
4Accepted3ms2464 KiB
5Accepted3ms2744 KiB
6Accepted3ms2940 KiB
7Wrong answer3ms3152 KiB
8Wrong answer3ms3180 KiB
9Accepted3ms3372 KiB
10Wrong answer3ms3784 KiB
11Accepted3ms3592 KiB
12Accepted3ms3908 KiB
subtask30/20
13Wrong answer3ms2616 KiB
14Accepted3ms2464 KiB
15Accepted3ms2744 KiB
16Accepted3ms2940 KiB
17Wrong answer3ms3152 KiB
18Wrong answer3ms3180 KiB
19Accepted3ms3372 KiB
20Wrong answer3ms3784 KiB
21Accepted3ms3592 KiB
22Accepted3ms3908 KiB
23Wrong answer3ms4240 KiB
24Accepted3ms4384 KiB
25Wrong answer3ms4392 KiB
26Wrong answer3ms4328 KiB
27Accepted3ms4444 KiB
28Wrong answer3ms4336 KiB
29Accepted4ms4452 KiB
30Accepted4ms4432 KiB
31Accepted3ms4388 KiB
subtask40/20
32Wrong answer3ms2616 KiB
33Accepted3ms2464 KiB
34Accepted3ms2744 KiB
35Accepted3ms2940 KiB
36Wrong answer3ms3152 KiB
37Wrong answer3ms3180 KiB
38Accepted3ms3372 KiB
39Wrong answer3ms3784 KiB
40Accepted3ms3592 KiB
41Accepted3ms3908 KiB
42Wrong answer3ms4240 KiB
43Accepted3ms4384 KiB
44Wrong answer3ms4392 KiB
45Wrong answer3ms4328 KiB
46Accepted3ms4444 KiB
47Wrong answer3ms4336 KiB
48Accepted4ms4452 KiB
49Accepted4ms4432 KiB
50Accepted3ms4388 KiB
51Wrong answer4ms5384 KiB
52Wrong answer4ms5592 KiB
53Wrong answer4ms5684 KiB
54Wrong answer4ms5820 KiB
55Wrong answer4ms6036 KiB
56Wrong answer8ms6120 KiB
57Wrong answer7ms6120 KiB
58Wrong answer9ms6076 KiB
59Wrong answer8ms6132 KiB
60Wrong answer8ms6348 KiB
61Accepted7ms6328 KiB
62Wrong answer7ms6480 KiB
63Wrong answer6ms6536 KiB
64Wrong answer7ms6436 KiB
65Wrong answer7ms6440 KiB
66Accepted13ms6532 KiB
67Accepted25ms6440 KiB
68Accepted28ms6432 KiB
69Accepted28ms6360 KiB
70Accepted26ms6440 KiB
subtask50/40
71Wrong answer3ms2616 KiB
72Accepted3ms2464 KiB
73Accepted3ms2744 KiB
74Accepted3ms2940 KiB
75Wrong answer3ms3152 KiB
76Wrong answer3ms3180 KiB
77Accepted3ms3372 KiB
78Wrong answer3ms3784 KiB
79Accepted3ms3592 KiB
80Accepted3ms3908 KiB
81Wrong answer3ms4240 KiB
82Accepted3ms4384 KiB
83Wrong answer3ms4392 KiB
84Wrong answer3ms4328 KiB
85Accepted3ms4444 KiB
86Wrong answer3ms4336 KiB
87Accepted4ms4452 KiB
88Accepted4ms4432 KiB
89Accepted3ms4388 KiB
90Wrong answer4ms5384 KiB
91Wrong answer4ms5592 KiB
92Wrong answer4ms5684 KiB
93Wrong answer4ms5820 KiB
94Wrong answer4ms6036 KiB
95Wrong answer8ms6120 KiB
96Wrong answer7ms6120 KiB
97Wrong answer9ms6076 KiB
98Wrong answer8ms6132 KiB
99Wrong answer8ms6348 KiB
100Accepted7ms6328 KiB
101Wrong answer7ms6480 KiB
102Wrong answer6ms6536 KiB
103Wrong answer7ms6436 KiB
104Wrong answer7ms6440 KiB
105Accepted13ms6532 KiB
106Accepted25ms6440 KiB
107Accepted28ms6432 KiB
108Accepted28ms6360 KiB
109Accepted26ms6440 KiB
110Wrong answer148ms21192 KiB
111Wrong answer130ms21436 KiB
112Wrong answer118ms21316 KiB
113Wrong answer130ms21336 KiB
114Wrong answer187ms21348 KiB
115Wrong answer135ms21384 KiB
116Wrong answer308ms21408 KiB
117Wrong answer351ms21508 KiB
118Wrong answer400ms21668 KiB
119Wrong answer360ms21700 KiB
120Wrong answer372ms21800 KiB
121Wrong answer351ms21840 KiB
122Wrong answer286ms21856 KiB
123Wrong answer256ms21760 KiB
124Wrong answer259ms21772 KiB
125Wrong answer225ms21716 KiB
126Time limit exceeded1.067s21884 KiB
127Accepted971ms21784 KiB
128Time limit exceeded1.062s13088 KiB
129Time limit exceeded1.05s21844 KiB
130Time limit exceeded1.059s13068 KiB
131Time limit exceeded1.062s13068 KiB
132Time limit exceeded1.078s13184 KiB