-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path988D. Points and Powers of Two.cpp
56 lines (46 loc) · 1.21 KB
/
988D. Points and Powers of Two.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
/*
Idea:
- Brute force.
- Based on the fact says we can't have more than 3 numbers with powers
of two as subtraction values between any of them, then we can do the
brute force.
*/
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 1;
int n;
long long a[N], powers[35];
vector<long long> sol, tmp;
bool check(long long x) {
for(int i = 0; i < tmp.size(); ++i)
if(!binary_search(powers, powers + 31, abs(tmp[i] - x)))
return false;
return true;
}
int main() {
powers[0] = 1;
for(int i = 1; i < 31; ++i)
powers[i] = powers[i - 1] * 2;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%lld", a + i);
sort(a, a + n);
for(int i = 0; i < n; ++i) {
long long cur = a[i];
tmp.push_back(cur);
for(int j = 0; j < 31; ++j) {
if(binary_search(a, a + n, cur + powers[j]) && check(cur + powers[j]))
tmp.push_back(cur + powers[j]);
if(binary_search(a, a + n, cur - powers[j]) && check(cur - powers[j]))
tmp.push_back(cur - powers[j]);
}
if(tmp.size() > sol.size())
sol.swap(tmp);
tmp.clear();
}
printf("%d\n", int(sol.size()));
for(int i = 0; i < sol.size(); ++i)
printf("%s%lld", i == 0 ? "" : " ", sol[i]);
puts("");
return 0;
}