http://www.codechef.com/problems/XORSUB Why am i getting only 30 points? Here is my code

#include
typedef long long int ll;
using namespace std;
int main()
{
ll t,k,n,i,nos,bitmask,pos,maxi;
cin>>t;
while(t–)
{
cin>>n>>k;
ll a[n],u=0,fp=0;
for(i=0;i<n;i++)
{
cin>>a[i];
}
nos=1<<n;
for(i=0;i<nos;i++,u=0)
{
pos=n-1;
bitmask=i;
while(bitmask>0)
{
if((bitmask&1)==1)
{
if(u==0)
{
u++;
fp=a[pos];
}
else
fp^=a[pos];
}
bitmask>>=1;
pos–;
}
if(u==0)
fp=0;
if(i==0)
maxi=k^fp;
else
{
if((k^fp)>maxi)
maxi=k^fp;
}
}
cout<<maxi<<’\n’;
}
return 0;
}

Check these links:

I have tested your code and an AC’ed code on 100 random test cases and AC’ed formulated the solutions whereas for your code it returns TLE

AC’ed CODE:

YOUR CODE:

Just check those test cases, and try to figure out where your code fails.

Use freopen for offline debugging:

#ifndef ONLINE_JUDGE
freopen("test.in", "r" , stdin);
freopen("test.out", "w", stdout);
#endif

Here you can find the code for test case generator, generate and test as many cases as you can:


Happy Debugging… :slight_smile: