Codechef September long
Exor problem (PALINT)
Getting wrong answer. Is anyone able to spot that monkey case where its failing?
(i have considered X= 0 exceptions)
#include
#include
#include
#define ll long long
using namespace std;
int main()
{
ll int N;
ll int X,max,a;
int T;
cin>>T;
while(T--)
{
map<ll int,ll int>m;
map<ll int,ll int>m2;
cin>>N>>X;
ll int list2[N];
//taking main count
for(ll int i=0;i<N;i++)
{
cin>>a;
list2[i]=a^X;
m[a]++;
m[list2[i]]++;
}
//taking only second list count
for(ll int i=0;i<N;i++)
{
m2[list2[i]]++;
}
//finding max frequency
ll int max=m.begin()->second;
ll int best=m.begin()->first;
for(auto x:m)
{
if(x.second>max)
{
max=x.second;
best=x.first;
}
}
if(X==0)
cout<<max/2<<" ";
else
cout<<max<<" ";
//shortlisting and finding best
for(auto x:m)
{
if(x.second==max)//shortlisting those numbers with max frequency
{
if(m2[x.first]<m2[best])//finding best(case where lesser operations required)
best=x.first;
}
}
if(X==0)
cout<<0;
else
cout<<m2[best]<<endl;
}
return 0;
}