-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_2194.cpp
More file actions
80 lines (77 loc) · 1.92 KB
/
cses_2194.cpp
File metadata and controls
80 lines (77 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/extc++.h>
using namespace std;
#define double long long
int mode = 0;
struct PT
{
double x, y;
PT(double x = 0, double y = 0) : x(x), y(y) {}
PT operator+(const PT &b) const
{
return PT(x + b.x, y + b.y);
}
PT operator-(const PT &b) const
{
return PT(x - b.x, y - b.y);
}
PT operator*(double b) const
{
return PT(x * b, y * b);
}
PT operator/(double b) const
{
return PT(x / b, y / b);
}
bool operator<(const PT &b) const
{
if (mode == 0)
return x != b.x ? x < b.x : y < b.y;
else if (mode == 1)
return y != b.y ? y < b.y : x < b.x;
else
return x + y != b.x + b.y ? x + y < b.x + b.y : x < b.x;
}
double dot(const PT &b) const
{
return x * b.x + y * b.y;
}
double cross(const PT &b) const
{
return x * b.y - y * b.x;
}
double abs2()
{
return x * x + y * y;
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long result = 8e18 + 87;
cin >> n;
vector<PT> points(n);
for (int i = 0; i < n; i++)
{
int64_t x, y;
cin >> x >> y;
points[i] = PT(x, y);
}
sort(points.begin(), points.end());
for (int i = 0; i < n; i++)
for (int j = 1; (j * j < n || j < 487) && i + j < n; j++)
result = min(result, (points[i] - points[i + j]).abs2());
mode = 1;
sort(points.begin(), points.end());
for (int i = 0; i < n; i++)
for (int j = 1; (j * j < n || j < 487) && i + j < n; j++)
result = min(result, (points[i] - points[i + j]).abs2());
mode = 2;
sort(points.begin(), points.end());
for (int i = 0; i < n; i++)
for (int j = 1; (j * j < n || j < 487) && i + j < n; j++)
result = min(result, (points[i] - points[i + j]).abs2());
cout << result << '\n';
return 0;
}