记录编号 158520 评测结果 AAAAAAAAAA
题目名称 [CQOI2013]新Nim游戏 最终得分 100
用户昵称 Gravatar真呆菌 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2015-04-15 17:51:11 内存使用 0.29 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. const int MaxBit = 31;
  5. const int N = 110;
  6.  
  7. int n,a[N],lb[N];
  8. long long res;
  9.  
  10. bool Check(int x){
  11. for(int i=MaxBit;~i;i--){
  12. if((x>>i)&1){
  13. if(!lb[i]){lb[i]=x;return 1;}
  14. else x^=lb[i];
  15. }
  16. }
  17. return x;
  18. }
  19.  
  20. int main(){
  21. #define Read
  22. #ifdef Read
  23. freopen("newnim.in","r",stdin);
  24. freopen("newnim.out","w",stdout);
  25. #endif
  26. scanf("%d",&n);
  27. for(int i=1;i<=n;i++) scanf("%d",&a[i]),res+=a[i];
  28. sort(a+1,a+n+1);
  29. for(int i=n;i>=1;i--)
  30. if(Check(a[i])) res-=a[i];
  31. if(res==0) res=-1;
  32. printf("%lld\n",res);
  33. return 0;
  34. }