Skip to content

Instantly share code, notes, and snippets.

@chinmaydd
Created December 8, 2014 17:09
Show Gist options
  • Save chinmaydd/bfbbdc4bbae9aee06f7d to your computer and use it in GitHub Desktop.
Save chinmaydd/bfbbdc4bbae9aee06f7d to your computer and use it in GitHub Desktop.
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<long long> v;
long long x;
for(int i=0;i<n;i++)
{
scanf("%lld",&x);
v.push_back(x);
}
sort(v.rbegin(),v.rend());
long long int sig=1;
while(sig<=v[0])
sig<<=1;
sig>>=1;
printf("%lld %lld", sig, v[0]);
for(int t=0;sig>=1;sig>>=1)
{
int i=t;
while(i<n && (v[i]&sig)==0)
i++;
if(i>=n)
continue;
swap(v[t],v[i]);
for(int j=0;j<n;++j)
{
if(j!=t && (v[j]&sig)!=0)
v[j]=v[j]^v[t];
}
t++;
}
long long int res=0;
for(int q=0;q<n;q++)
{
res=res^v[q];
}
printf("%lld\n",res);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment