100172024-03-24 11:04:07111Rajzcpp17Time limit exceeded 20/1001.078s30144 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

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());
	vector<vector<int>>g(N);
	vector<int>p;
	auto dfs=[&](auto self,int i,int j,int t)->bool{
		if(j==t){
			p.push_back(j);
			return true;
		}
		for(int k:g[j]){
			if(k==i){
				continue;
			}
			if(self(self,j,k,t)){
				p.push_back(j);
				return true;
			}
		}
		return false;
	};
	auto check=[&]()->bool{
		int c=0;
		for(int i=0;i<p.size();i++){
			int j=(i+1)%p.size();
			c+=test(v[p[i]].x,v[p[i]].y,v[p[j]].x,v[p[j]].y,0,0,1e9+7,1e9+9);
		}
		return c%2;
	};
	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;
			p.clear();
			if(dfs(dfs,-1,a,b)){
				if(check()){
					cout<<ans<<'\n';
					return 0;
				}
			}
			else {
				g[a].push_back(b);
				g[b].push_back(a);
			}
			i++;
		}
	}
	cout<<-1<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2080 KiB
subtask220/20
3Accepted3ms2292 KiB
4Accepted3ms2396 KiB
5Accepted3ms2612 KiB
6Accepted3ms2692 KiB
7Accepted3ms2632 KiB
8Accepted3ms2892 KiB
9Accepted3ms2880 KiB
10Accepted3ms3004 KiB
11Accepted3ms3220 KiB
12Accepted3ms3192 KiB
subtask30/20
13Accepted3ms2292 KiB
14Accepted3ms2396 KiB
15Accepted3ms2612 KiB
16Accepted3ms2692 KiB
17Accepted3ms2632 KiB
18Accepted3ms2892 KiB
19Accepted3ms2880 KiB
20Accepted3ms3004 KiB
21Accepted3ms3220 KiB
22Accepted3ms3192 KiB
23Accepted3ms3476 KiB
24Accepted3ms3676 KiB
25Accepted3ms3648 KiB
26Accepted3ms3860 KiB
27Accepted3ms3956 KiB
28Accepted3ms4084 KiB
29Accepted3ms4064 KiB
30Accepted3ms4164 KiB
31Accepted3ms4296 KiB
subtask40/20
32Accepted3ms2292 KiB
33Accepted3ms2396 KiB
34Accepted3ms2612 KiB
35Accepted3ms2692 KiB
36Accepted3ms2632 KiB
37Accepted3ms2892 KiB
38Accepted3ms2880 KiB
39Accepted3ms3004 KiB
40Accepted3ms3220 KiB
41Accepted3ms3192 KiB
42Accepted3ms3476 KiB
43Accepted3ms3676 KiB
44Accepted3ms3648 KiB
45Accepted3ms3860 KiB
46Accepted3ms3956 KiB
47Accepted3ms4084 KiB
48Accepted3ms4064 KiB
49Accepted3ms4164 KiB
50Accepted3ms4296 KiB
51Accepted4ms4596 KiB
52Accepted3ms4600 KiB
53Accepted3ms4632 KiB
54Accepted3ms4764 KiB
55Accepted3ms4772 KiB
56Accepted3ms4680 KiB
57Accepted3ms4680 KiB
58Accepted3ms4688 KiB
59Accepted3ms4692 KiB
60Accepted3ms4724 KiB
61Accepted3ms4700 KiB
62Accepted3ms4732 KiB
63Accepted3ms4744 KiB
64Accepted3ms4744 KiB
65Accepted4ms4784 KiB
66Accepted7ms4764 KiB
67Accepted8ms5020 KiB
68Accepted8ms5012 KiB
69Accepted10ms4988 KiB
70Accepted8ms4988 KiB
subtask50/40
71Accepted3ms2292 KiB
72Accepted3ms2396 KiB
73Accepted3ms2612 KiB
74Accepted3ms2692 KiB
75Accepted3ms2632 KiB
76Accepted3ms2892 KiB
77Accepted3ms2880 KiB
78Accepted3ms3004 KiB
79Accepted3ms3220 KiB
80Accepted3ms3192 KiB
81Accepted3ms3476 KiB
82Accepted3ms3676 KiB
83Accepted3ms3648 KiB
84Accepted3ms3860 KiB
85Accepted3ms3956 KiB
86Accepted3ms4084 KiB
87Accepted3ms4064 KiB
88Accepted3ms4164 KiB
89Accepted3ms4296 KiB
90Accepted4ms4596 KiB
91Accepted3ms4600 KiB
92Accepted3ms4632 KiB
93Accepted3ms4764 KiB
94Accepted3ms4772 KiB
95Accepted3ms4680 KiB
96Accepted3ms4680 KiB
97Accepted3ms4688 KiB
98Accepted3ms4692 KiB
99Accepted3ms4724 KiB
100Accepted3ms4700 KiB
101Accepted3ms4732 KiB
102Accepted3ms4744 KiB
103Accepted3ms4744 KiB
104Accepted4ms4784 KiB
105Accepted7ms4764 KiB
106Accepted8ms5020 KiB
107Accepted8ms5012 KiB
108Accepted10ms4988 KiB
109Accepted8ms4988 KiB
110Accepted108ms29176 KiB
111Accepted100ms29236 KiB
112Accepted98ms29272 KiB
113Accepted96ms29244 KiB
114Accepted98ms29272 KiB
115Accepted101ms29288 KiB
116Accepted86ms29312 KiB
117Accepted85ms29360 KiB
118Accepted86ms29508 KiB
119Accepted86ms29456 KiB
120Accepted86ms29492 KiB
121Accepted83ms29484 KiB
122Accepted90ms29504 KiB
123Accepted89ms29528 KiB
124Accepted90ms29700 KiB
125Accepted87ms30144 KiB
126Time limit exceeded1.054s17164 KiB
127Time limit exceeded1.07s17140 KiB
128Time limit exceeded1.059s17152 KiB
129Time limit exceeded1.062s17220 KiB
130Time limit exceeded1.065s17228 KiB
131Time limit exceeded1.074s17192 KiB
132Time limit exceeded1.078s17236 KiB