14年论文题
贪心+线性基搞一搞
忘了开longlong一直WA好智障阿QAQ
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; #define rep(i,l,r) for(int i=l;i<=r;i++) #define per(i,r,l) for(int i=r;i>=l;i--) #define mmt(a,v) memset(a,v,sizeof(a)) typedef long long ll; int a[105]; int base[40]; bool ins(int x){ per(i,30,0) if((x>>i)&1){ if(!base[i]){ base[i]=x; return true; }else x^=base[i]; } return !(!x); } int main(){ freopen("a.in","r",stdin); int n;scanf("%d",&n); ll ans=0,sum; rep(i,1,n)scanf("%d",&a[i]),ans+=a[i]; sum=ans; sort(a+1,a+1+n); per(i,n,1) if(ins(a[i]))ans-=a[i]; if(sum==ans)ans=-1; printf("%lld\n",ans); return 0; }