-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9015.cpp
84 lines (67 loc) · 1.72 KB
/
9015.cpp
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
81
82
83
84
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
int xxxx[]={-1,0,1,0};
int yyyy[]={0,1,0,-1};
typedef pair<int,int> pii;
ll square(pii a, pii b) {
return (b.first - a.first) * (b.first - a.first) + (b.second - a.second) * (b.second - a.second);
}
pii points[3000];
int N;
bool find(int x, int y) {
int l = 0, r = N;
while (l + 1 < r) {
int m = (l+r)/2;
auto [fx,fy] = points[m];
if (fx == x && fy == y) return true;
if (fx > x) {
r = m;
} else if (fx == x) {
if (fy > y) {
r = m;
} else {
l = m;
}
} else {
l = m;
}
}
return false;
}
void solve(){
cin >> N;
for (int i = 0; i < N; i++){
auto &[x,y] = points[i];
cin >> x >> y;
}
sort(points, points+N);
ll result = 0;
for (int i = 0; i < N; i++) {
auto [lx, ly] = points[i];
for (int j = i + 1; j < N; j++) {
auto [rx, ry] = points[j];
if (square(points[i], points[j]) <= result) continue;
int flx = lx-(ry-ly);
int fly = ly+(rx-lx);
int frx = rx-(ry-ly);
int fry = ry+(rx-lx);
if (find(flx, fly) && find(frx, fry)) result = square(points[i], points[j]);
}
}
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T; cin >> T;
while (T--) {
solve();
cout << '\n';
}
return 0;
}