109162024-04-18 20:50:33gortomiRajzcpp17Wrong answer 0/10097ms30024 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> p, r;
int n;
int get(int v)
{
    return p[v] == 0 ? v : p[v] = get(p[v]);
}
void unio(int a, int b)
{
    a = get(a);
    b = get(b);
    if(a != b)
    {
        if(r[a] < r[b]) swap(a, b);
        p[b] = a;
        if(r[a] == r[b]) r[a]++;
    }
}
struct val
{
    ll a, b, d;
};
bool insc(ll xa, ll xb, ll ya, ll yb)
{
    if(ya == yb) return 0;
    if(xb != xa)
    {
        ll x = xa * (yb - ya) + -ya * (xb - xa);
        ll l = xa * (yb - ya), r = xb * (yb - ya);
        if(l > r) swap(l, r);
        return ((x > 0) ^ (ya > yb)) && x >= l && x <= r;
    }
    return xa > 0 && max(ya, yb) > 0 && min(ya, yb) < 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    p.resize(2 * n + 1);
    r.resize(2 * n + 1);
    vector<ll> x(n + 1), y(n + 1);
    vector<val> e;
    for(int i = 1; i <= n; i++)
    {
        cin >> x[i] >> y[i];
        for(int j = 1; j < i; j++)
        {
            ll dx = x[i] - x[j], dy = y[i] - y[j];
            e.push_back({j, i, dx * dx + dy * dy});
        }
    }
    sort(e.begin(), e.end(), [](val a, val b)
    {
        return a.d < b.d;
    });
    for(auto [a, b, d] : e)
    {
        bool g = insc(x[a], x[b], y[a], y[b]);
        //cout << a << " " << b << " " << d << " " << g << "\n";
        if(g)
        {
            unio(a, b + n);
            unio(a + n, b);
        }
        else
        {
            unio(a, b);
            unio(a + n, b + n);
        }
        if(get(a) == get(a + n))
        {
            cout << d << "\n";
            return 0;
        }
    }
    cout << "-1\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2068 KiB
subtask20/20
3Accepted3ms2276 KiB
4Wrong answer3ms2316 KiB
5Accepted3ms2448 KiB
6Accepted3ms2672 KiB
7Wrong answer3ms2768 KiB
8Accepted3ms2852 KiB
9Wrong answer3ms2984 KiB
10Wrong answer3ms3196 KiB
11Accepted3ms3268 KiB
12Accepted3ms3272 KiB
subtask30/20
13Accepted3ms2276 KiB
14Wrong answer3ms2316 KiB
15Accepted3ms2448 KiB
16Accepted3ms2672 KiB
17Wrong answer3ms2768 KiB
18Accepted3ms2852 KiB
19Wrong answer3ms2984 KiB
20Wrong answer3ms3196 KiB
21Accepted3ms3268 KiB
22Accepted3ms3272 KiB
23Accepted3ms3420 KiB
24Accepted3ms3612 KiB
25Wrong answer3ms3824 KiB
26Wrong answer3ms3912 KiB
27Accepted3ms4124 KiB
28Accepted3ms4220 KiB
29Accepted3ms4436 KiB
30Accepted3ms4432 KiB
31Accepted3ms4412 KiB
subtask40/20
32Accepted3ms2276 KiB
33Wrong answer3ms2316 KiB
34Accepted3ms2448 KiB
35Accepted3ms2672 KiB
36Wrong answer3ms2768 KiB
37Accepted3ms2852 KiB
38Wrong answer3ms2984 KiB
39Wrong answer3ms3196 KiB
40Accepted3ms3268 KiB
41Accepted3ms3272 KiB
42Accepted3ms3420 KiB
43Accepted3ms3612 KiB
44Wrong answer3ms3824 KiB
45Wrong answer3ms3912 KiB
46Accepted3ms4124 KiB
47Accepted3ms4220 KiB
48Accepted3ms4436 KiB
49Accepted3ms4432 KiB
50Accepted3ms4412 KiB
51Accepted3ms4792 KiB
52Accepted3ms4816 KiB
53Accepted3ms4812 KiB
54Accepted3ms5108 KiB
55Accepted3ms5112 KiB
56Accepted3ms5108 KiB
57Accepted3ms5044 KiB
58Accepted3ms5036 KiB
59Accepted3ms5008 KiB
60Accepted3ms5272 KiB
61Wrong answer3ms5220 KiB
62Wrong answer3ms5212 KiB
63Wrong answer3ms5244 KiB
64Wrong answer3ms5252 KiB
65Wrong answer3ms5216 KiB
66Accepted4ms5220 KiB
67Accepted4ms5496 KiB
68Accepted4ms5500 KiB
69Accepted3ms5532 KiB
70Accepted3ms5556 KiB
subtask50/40
71Accepted3ms2276 KiB
72Wrong answer3ms2316 KiB
73Accepted3ms2448 KiB
74Accepted3ms2672 KiB
75Wrong answer3ms2768 KiB
76Accepted3ms2852 KiB
77Wrong answer3ms2984 KiB
78Wrong answer3ms3196 KiB
79Accepted3ms3268 KiB
80Accepted3ms3272 KiB
81Accepted3ms3420 KiB
82Accepted3ms3612 KiB
83Wrong answer3ms3824 KiB
84Wrong answer3ms3912 KiB
85Accepted3ms4124 KiB
86Accepted3ms4220 KiB
87Accepted3ms4436 KiB
88Accepted3ms4432 KiB
89Accepted3ms4412 KiB
90Accepted3ms4792 KiB
91Accepted3ms4816 KiB
92Accepted3ms4812 KiB
93Accepted3ms5108 KiB
94Accepted3ms5112 KiB
95Accepted3ms5108 KiB
96Accepted3ms5044 KiB
97Accepted3ms5036 KiB
98Accepted3ms5008 KiB
99Accepted3ms5272 KiB
100Wrong answer3ms5220 KiB
101Wrong answer3ms5212 KiB
102Wrong answer3ms5244 KiB
103Wrong answer3ms5252 KiB
104Wrong answer3ms5216 KiB
105Accepted4ms5220 KiB
106Accepted4ms5496 KiB
107Accepted4ms5500 KiB
108Accepted3ms5532 KiB
109Accepted3ms5556 KiB
110Accepted86ms29684 KiB
111Wrong answer86ms29736 KiB
112Accepted82ms29784 KiB
113Accepted85ms29672 KiB
114Accepted82ms29664 KiB
115Wrong answer85ms29712 KiB
116Accepted90ms29716 KiB
117Accepted85ms29724 KiB
118Accepted89ms29716 KiB
119Accepted85ms29716 KiB
120Accepted89ms29712 KiB
121Accepted90ms29684 KiB
122Wrong answer90ms29740 KiB
123Wrong answer85ms29736 KiB
124Wrong answer89ms29712 KiB
125Wrong answer85ms29888 KiB
126Accepted93ms30016 KiB
127Accepted93ms30020 KiB
128Accepted96ms30024 KiB
129Accepted93ms29884 KiB
130Accepted97ms29928 KiB
131Accepted75ms29968 KiB
132Accepted97ms29976 KiB