istinishat

Gauss Elimination for xor

Jan 14th, 2019
570
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //https://codeforces.com/contest/1101/problem/G
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define MAX 200005
  7. #define ll long long
  8.  
  9. ll a[MAX];
  10. vector<bitset<64> >v;
  11.  
  12. ll gauss(int n,int m)
  13. {
  14.     int col=m-1,row=0,i,j;
  15.     ll ans=0;
  16.     for(;col>=0 && row<n;col--){
  17.         for(i=row;i<n;i++){
  18.             if(v[i][col]){
  19.                 swap(v[i],v[row]);
  20.                 break;
  21.             }
  22.         }
  23.         if(!v[row][col])continue;
  24.  
  25.         for(i=0;i<n;i++){
  26.             if(i==row)continue;
  27.             if(v[i][col])
  28.                 v[i]^=v[row];
  29.         }
  30.         row++;
  31.     }
  32.  
  33.  
  34.  
  35.     return row;
  36. }
  37.  
  38. int main()
  39. {
  40.     //freopen("input.txt","r",stdin);
  41.     int i,j,n;
  42.     ll xx=0;
  43.     scanf("%d",&n);
  44.     for(i=0;i<n;i++){
  45.         scanf("%lld",&a[i]);
  46.         xx^=a[i];
  47.     }
  48.     if(xx==0)return cout<<-1<<endl,0;
  49.  
  50.     for(i=0;i<n;i++){
  51.         bitset<64>x;
  52.         for(j=0;j<64;j++){
  53.             if(a[i] & (1LL<<j))x[j]=1;
  54.             else x[j]=0;
  55.         }
  56.         v.push_back(x);
  57.     }
  58.  
  59.     ll ans=gauss(n,64);
  60.     cout<<ans<<endl;
  61. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×