MYSARA Solution Explained

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;

}

You’ve written continue; instead of break;. continue; just goes to the next value in the loop, whereas break; ends the loop

Can Someone please help me out on this.
I’m not sure if my approach is wrong or i did some mistake in writing code. The Code seems clear and understandable for everyone. So please give it a look .
https://www.codechef.com/viewsolution/30665859

Thanks for the help. I feel completely dumb now.

plz tell what is wrong with my code

Why answer is 0 when array is sorted.
and why b[i] & b[i+1] != b[i]

Why ans is 0 when array is sorted
and what’s with this condition b[i] & b[i+1] != b[i]

consider b1=7 and b2=8;
binary representation of 7 is 0111
binary representation of 8 is 1000
we need an element a2 such that b1|a2=b2
b1-0 1 1 1
a2-? ? ? ?
---------------or operation
b2-1 0 0 0
--------------
if we observe the example,we can conlcude that
there is no element a2 which satisfies b1|a2=b2;
so answer must be 0;

Could someone pl tell why my solution is wrong
https://www.codechef.com/viewsolution/30661393

But why do we need to check set bits at same position of a and OR(a,b).
if there is 1 in a there will surely be 1 in OR(a,b).That means we only need to check the no. of 1’s in a and for each 1 in a there will be 2 possibilities (i.e, either 0 or 1).

Hi
Can u please help me
please tell me what is wrong with my code for MYSARA problem:
https://www.codechef.com/viewsolution/30719423

Try the test case

2
3
1 4 3
2
1 3

Thanks a lot for helping .

So we have to do two things here-
1)To check if Bi is the Subset of Bi+1.
2)count number of set bits in Bi and multiply them to get the answer.

Will this work?