100182024-03-24 11:21:55111Rajzcpp17Accepted 20/100127ms44280 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct DSU {
	vector<int> v;
	vector<vector<int>> c;

	DSU(int n) : v(n), c(n) {
		for (int i = 0; i < n; i++) {
			v[i] = i;
			c[i].push_back(i);
		}
	}

	int find(int a) {
		return v[a] == a ? a : v[a] = find(v[a]);
	}

	bool unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) {
			return true;
		}
		if (c[a].size() < c[b].size()) {
			swap(a, b);
		}
		c[a].insert(c[a].end(), c[b].begin(), c[b].end());
		c[b].clear();
		v[b] = a;
		return false;
	}
};

int sign(int x) {
	return (x > 0) - (x < 0);
}

int cross(int x1, int y1, int x2, int y2) {
	return x1 * y2 - y1 * x2;
}

int orient(int x1, int y1, int x2, int y2, int x3, int y3) {
	return sign(cross(x1 - x2, y1 - y2, x3 - x2, y3 - y2));
}

bool test(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
	int o1 = orient(x1, y1, x2, y2, x3, y3);
	int o2 = orient(x1, y1, x2, y2, x4, y4);
	int o3 = orient(x3, y3, x4, y4, x1, y1);
	int o4 = orient(x3, y3, x4, y4, x2, y2);
	return o1 != o2 && o3 != o4;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	struct Pt{ 
		int x,y; 
	};
	vector<Pt>v(N);
	for(int i=0;i<N;i++){
		cin>>v[i].x>>v[i].y;
	}
	vector<pair<int,pair<int,int>>>e;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			e.emplace_back((v[i].x-v[j].x)*(v[i].x-v[j].x)+(v[i].y-v[j].y)*(v[i].y-v[j].y),make_pair(i,j));
		}
	}
	sort(e.begin(),e.end());
	DSU dsu(N);
	vector<vector<int>>dp(N,vector<int>(N,0));
	auto T=[&](int i,int j)->bool{
		return test(v[i].x,v[i].y,v[j].x,v[j].y,0,0,1e9+7,1e9+9);
	};
	for(int i=0;i<e.size();){
		int ans=e[i].first;
		while(i<e.size()&&e[i].first==ans){
			auto[a,b]=e[i].second;
			int ca=dsu.find(a),cb=dsu.find(b);
			if(ca==cb){
				if(dp[a][b]^T(a,b)){
					cout<<ans<<'\n';
					return 0;
				}
			}
			else {
				int x=T(a,b);
				for(int i:dsu.c[ca]){
					for(int j:dsu.c[cb]){
						dp[i][j]=dp[j][i]=dp[i][a]^x^dp[j][b];
					}
				}
				dsu.unite(a,b);
			}
			i++;
		}
	}
	cout<<-1<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2060 KiB
subtask220/20
3Accepted3ms2284 KiB
4Accepted3ms2460 KiB
5Accepted3ms2672 KiB
6Accepted3ms2884 KiB
7Accepted3ms3092 KiB
8Accepted3ms3324 KiB
9Accepted3ms3416 KiB
10Accepted3ms3404 KiB
11Accepted2ms3400 KiB
12Accepted2ms3404 KiB
subtask30/20
13Accepted3ms2284 KiB
14Accepted3ms2460 KiB
15Accepted3ms2672 KiB
16Accepted3ms2884 KiB
17Accepted3ms3092 KiB
18Accepted3ms3324 KiB
19Accepted3ms3416 KiB
20Accepted3ms3404 KiB
21Accepted2ms3400 KiB
22Accepted2ms3404 KiB
23Accepted3ms3384 KiB
24Accepted3ms3384 KiB
25Accepted3ms3472 KiB
26Accepted3ms3608 KiB
27Accepted2ms3688 KiB
28Accepted3ms3688 KiB
29Accepted3ms3688 KiB
30Accepted3ms3824 KiB
31Accepted3ms4028 KiB
subtask40/20
32Accepted3ms2284 KiB
33Accepted3ms2460 KiB
34Accepted3ms2672 KiB
35Accepted3ms2884 KiB
36Accepted3ms3092 KiB
37Accepted3ms3324 KiB
38Accepted3ms3416 KiB
39Accepted3ms3404 KiB
40Accepted2ms3400 KiB
41Accepted2ms3404 KiB
42Accepted3ms3384 KiB
43Accepted3ms3384 KiB
44Accepted3ms3472 KiB
45Accepted3ms3608 KiB
46Accepted2ms3688 KiB
47Accepted3ms3688 KiB
48Accepted3ms3688 KiB
49Accepted3ms3824 KiB
50Accepted3ms4028 KiB
51Accepted4ms4820 KiB
52Accepted3ms4756 KiB
53Accepted3ms4788 KiB
54Accepted3ms4712 KiB
55Accepted4ms5000 KiB
56Accepted3ms4964 KiB
57Accepted3ms4900 KiB
58Accepted3ms4896 KiB
59Accepted4ms5196 KiB
60Accepted3ms5184 KiB
61Accepted3ms5316 KiB
62Accepted3ms5284 KiB
63Accepted3ms5316 KiB
64Accepted3ms5340 KiB
65Accepted3ms5312 KiB
66Accepted3ms5348 KiB
67Accepted3ms5344 KiB
68Accepted3ms5596 KiB
69Accepted4ms5484 KiB
70Accepted3ms5512 KiB
subtask50/40
71Accepted3ms2284 KiB
72Accepted3ms2460 KiB
73Accepted3ms2672 KiB
74Accepted3ms2884 KiB
75Accepted3ms3092 KiB
76Accepted3ms3324 KiB
77Accepted3ms3416 KiB
78Accepted3ms3404 KiB
79Accepted2ms3400 KiB
80Accepted2ms3404 KiB
81Accepted3ms3384 KiB
82Accepted3ms3384 KiB
83Accepted3ms3472 KiB
84Accepted3ms3608 KiB
85Accepted2ms3688 KiB
86Accepted3ms3688 KiB
87Accepted3ms3688 KiB
88Accepted3ms3824 KiB
89Accepted3ms4028 KiB
90Accepted4ms4820 KiB
91Accepted3ms4756 KiB
92Accepted3ms4788 KiB
93Accepted3ms4712 KiB
94Accepted4ms5000 KiB
95Accepted3ms4964 KiB
96Accepted3ms4900 KiB
97Accepted3ms4896 KiB
98Accepted4ms5196 KiB
99Accepted3ms5184 KiB
100Accepted3ms5316 KiB
101Accepted3ms5284 KiB
102Accepted3ms5316 KiB
103Accepted3ms5340 KiB
104Accepted3ms5312 KiB
105Accepted3ms5348 KiB
106Accepted3ms5344 KiB
107Accepted3ms5596 KiB
108Accepted4ms5484 KiB
109Accepted3ms5512 KiB
110Accepted107ms44084 KiB
111Accepted104ms44248 KiB
112Accepted104ms44136 KiB
113Accepted104ms44160 KiB
114Accepted105ms44184 KiB
115Accepted112ms44144 KiB
116Accepted97ms44160 KiB
117Accepted92ms44124 KiB
118Accepted90ms44096 KiB
119Accepted93ms44096 KiB
120Accepted92ms44108 KiB
121Accepted92ms44096 KiB
122Accepted90ms44096 KiB
123Accepted90ms44136 KiB
124Accepted90ms44136 KiB
125Accepted90ms44280 KiB
126Accepted111ms44096 KiB
127Accepted107ms44100 KiB
128Accepted111ms44096 KiB
129Accepted108ms44112 KiB
130Accepted107ms44240 KiB
131Accepted127ms44124 KiB
132Accepted109ms44128 KiB