My approach was B[0] =A[0]. We know that B[i] = B[i-1] V A[i]. If B[i-1][j]==0 then A[i][j]=b[i][j] and we have no option. If B[i-1][j]==1 then B[i][j]=1 no whatter the value of A[i][j]. Hence we have two options. using product rule we can say that A[i] can have 2^(number of set b its in B[i-1]). The only case where the array will not be defined will be if B[i-1][j]==1 and B[i][j]==0, since that is not possible using or operation. In that case output 0. else output product of number of possible A[i] for each i from 1 to n. But I am getting wrong answer, below is my code, can someone please tell me the error in my logic/code. Help will be appreciated!
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long int
ll MOD = 1000000007;
long long int fast_exp(long long int base, long long int exp) {
long long int res = 1;
while(exp>0) {
if(exp&1) {
res = (res*base)%MOD;
}
base = (base*base)%MOD;
exp = exp>>1;
}
return res%MOD;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--){
ll n, temp;
cin>>n;
vector<bitset<32>> b(n);
for(ll i=0; i<n; i++){
cin>>temp;
b[i] = temp;
}
ll count = 1;
bool flag = true;
for(ll i=1; i<n; i++){
count = (count*fast_exp(2, b[i-1].count()))%MOD;
if((b[i-1]&(~b[i]))!=0) {
cout<<0<<'\n';
flag = false;
continue;
}
}
if(flag) cout<<count<<"\n";
}
return 0;
}