MYSARA problem

Getting WA.Please help.

#include<bits/stdc++.h>
using namespace std;

int power(long long int x,long long int y,long long int mod)
{
long long int res=1;
x=x%mod;
while(y>0)
{
if(y&1)
{
res=(res*x)%mod;
}

	y=y>>1;
	x=(x*x)%mod;
}
return res;

}
int main()
{
long long T,t,a,five=5,two=2,ans=0;
cin>>T;
while(T–)
{
cin>>t;
long long int arr[t];
for (long long int i = 0; i < t; ++i)
{
cin>>arr[i];
}
for (long long int i = 1; i < t; ++i)
{
ans+=__builtin_popcount(arr[i]&arr[i-1]);
}
cout<<power(2,ans,1000000007)<<endl;
ans=0;
}
}

Please refer to my solution, its very similar to yours.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define mod 1000000007
#define pb push_back
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)

ll mm(ll a, ll b) 
{ 
    ll res = 0; 
    a %= mod; 
    while (b) 
    { 
        if (b & 1) 
            res = (res + a) % mod; 
        a = (2 * a) % mod; 
        b >>= 1;
    } 
    return res; 
}

int main()
{
	zapp;
	ll t;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll i,b[n];
		for(i=0;i<n;i++)
		{
			cin>>b[i];
		}
		bool inc = true;
		for(i=1;i<n;i++)
		{
			if(b[i]<b[i-1])
				inc = false;
		}
		if(!inc)
		{
			cout<<0<<"\n";
			continue;
		}
		ll nd[n];
		nd[0] = 1;
		for(i=1;i<n;i++)
		{
			nd[i] = pow(2,__builtin_popcount(b[i] & b[i-1]));
		}
		ll ans = 1;
		for(i=0;i<n;i++)
		{
			ans = mm(ans,nd[i]);
			ans = ans % mod;
		}
		cout<<ans<<"\n";
	}
}

You are missing the condition that the array should not have an extrema, i.e minima or maxima, the array should be increasing. A[i] <= A[j] , where i<j

1 Like

Ohh…Thanks.
That was a very silly mistake :slightly_smiling_face:

Thanks and yeah code is almost similar.

Anytime :slight_smile: