p2460:
#include<cstdio> #include<algorithm> using namespace std; #define N 1001 typedef long long ll; struct Point{ll p;int v;}a[N]; bool operator < (const Point &a,const Point &b){return a.v>b.v;} int n,ans; ll base[64]; int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%lld%d",&a[i].p,&a[i].v); sort(a+1,a+n+1); for(int i=1;i<=n;++i) { for(int j=63;j>=0;--j) if((a[i].p>>j)&1) { if(!base[j]) { base[j]=a[i].p; break; } a[i].p^=base[j]; } if(a[i].p) ans+=a[i].v; } printf("%d ",ans); return 0; }
p3105:
#include<cstdio> #include<algorithm> using namespace std; #define N 101 typedef long long ll; int n,a[N],base[32]; ll ans,sum; bool cmp(const int &a,const int &b){return a>b;} int main() { scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%d",&a[i]); sum+=(ll)a[i]; } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;++i) { int t=a[i]; for(int j=31;j>=0;--j) if((t>>j)&1) { if(!base[j]) { base[j]=t; break; } t^=base[j]; } if(!t) ans+=(ll)a[i]; } printf("%lld ",ans==sum?(-1):ans); return 0; }