-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsos dp.cpp
More file actions
61 lines (59 loc) · 1.21 KB
/
Copy pathsos dp.cpp
File metadata and controls
61 lines (59 loc) · 1.21 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
//computable number//codeforces
//complexity O(n*2^n)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int MX=5000005;
const ll mod=1e9;
const ll inf=1e18;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
int d[MX],dp[MX],f[MX];
int main()
{
FasterIO;
int i,j,k,n,m,x,y,tc;
cin>>n;
for(i=0; i<n; i++)
{
cin>>d[i];
f[d[i]]++;
}
for(int msk=0; msk<(1LL<<22); msk++)
{
dp[msk]=f[msk];
}
for(i=0;i<=22;i++)
{
for(int msk=0;msk<(1LL<<22);msk++)
{
if(msk&(1LL<<i))
dp[msk]+=dp[msk^(1LL<<i)];
}
}
for(i=0; i<n; i++)
{
x=((1LL<<22)-1)^d[i];
if(dp[x]==0)
{
cout<<"-1 ";
continue;
}
int msk=x;
for(j=22; j>=0; j--)
{
if((msk&(1<<j))&&dp[msk^(1LL<<j)])
{
msk=msk^(1LL<<j);
}
}
cout<<msk<<" ";
}
cout<<endl;
return 0;
}