-
Notifications
You must be signed in to change notification settings - Fork 2
/
binary_equivalent.cpp
74 lines (70 loc) · 1.19 KB
/
binary_equivalent.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
#include<iostream>
#include<bits/stdc++.h>
#define PI 3.141592653589793
#define MAX 1000000007
using namespace std;
void flipbits(int i,vector<int> &arr1,int k,int x,int &t)
{
if(i == k)
{
if(x == 0)
t++;
return;
}
flipbits(i+1,arr1,k,x+arr1[i],t);
flipbits(i+1,arr1,k,x,t);
}
int main(void)
{
int i,j=0,n,x=0,ct=0,t=0;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
vector<int> arr(n);
for(auto &i:arr)
{
cin >> i;
}
for(i=0;i<n;i++)
{
if(arr[i] > x)
x = arr[i];
}
while(x)
{
ct++;
x>>=1;
}
vector arr1(n,0);
for(i=0;i<n;i++)
{
while(arr[i])
{
if(arr[i]&1)
arr1[i]++;
arr[i]>>=1;
}
}
for(i=0;i<n;i++)
{
arr1[j] = ct-2*arr1[i];
if(arr1[j]==0)
continue;
else
j++;
}
flipbits(0,arr1,j,0,t);
t -= 1;
t = t*(1+n-j)+(1<<(n-j))-1;
vector bits(ct,0);
i=0;
while(t > 0)
{
bits[i] = t & 1;
t >>= 1;
i++;
}
for(j=ct-1;j>=0;j--)
cout<<bits[j];
return 0;
}