1013B codeforces - And


1013B codeforces - And






Solution in C++


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

typedef long long int lli;
#define pii pair<int,int>

int n,t,lol,x,sol=3;
map<int,int> all,an;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>x;
    int nn[n],mm[n];
    for(int i=0;i<n;i++)
    {
        cin>>nn[i];
        all[nn[i] ]++;
        if(all[nn[i]]>=2)lol=1;
    }
    if(!lol)
    {
        for(int i=0;i<n;i++)
        {
            if(nn[i]!=(nn[i]&x) )
            {
                an[ (nn[i]&x) ]++;
                if(all[ (nn[i]&x) ]>=1) sol=min(sol,1);
                else if(an[ (nn[i]&x) ]>=2) sol=min(sol,2);
            }
        }
    }
    else return cout<<0,0;
    cout<<((sol==3)?-1:sol);
    return 0;
}
Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق