a53

complementar

a53
Oct 15th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("complementar.in");
  5. ofstream fout("complementar.out");
  6.  
  7. int n, m, p2, a[200005];
  8. char mat[35];
  9. long long nr;
  10. long long xorPairCount(int arr[], int n, int x)
  11. {
  12. long long result = 0;
  13. unordered_map<long long, long long> mp;
  14.  
  15. for (int i=0; i<n ; i++)
  16. {
  17. int curr_xor = x^arr[i];
  18. if (mp.find(curr_xor) != mp.end())
  19. result += mp[curr_xor];
  20. mp[arr[i]]++;
  21. }
  22. return result;
  23. }
  24.  
  25. int main()
  26. {
  27. int i;
  28. fin>>n>>m;
  29. p2=(1<<m)-1;
  30. fin.get();
  31. for(i=0;i<n;i++)
  32. {
  33. fin>>mat;
  34. int dec_value=0;
  35. int base=1;
  36. for(int k=m-1;k>=0;k--)
  37. {
  38. dec_value+=((int)(mat[k]-'0'))*base;
  39. base=base*2;
  40. }
  41. a[i]=dec_value;
  42. }
  43. nr=xorPairCount(a,n,p2);
  44. fout<<nr;
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment