Alex_tz307

Perechi infopro X

Nov 14th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("perechi.in");
  7. ofstream fout("perechi.out");
  8.  
  9. int val(char ch) {
  10.     if(isdigit(ch))
  11.         return ch - '0';
  12.     return ch - 'A' + 10;
  13. }
  14.  
  15. int32_t main() {
  16.     fin.sync_with_stdio(false);
  17.     fout.sync_with_stdio(false);
  18.     fin.tie(nullptr);
  19.     fout.tie(nullptr);
  20.     string s;
  21.     vector < int > f(65536);
  22.     int ans = 0;
  23.     while(fin >> s) {
  24.         int mask1 = 0, mask2 = 0;
  25.         for(char x : s)
  26.             mask1 |= (1 << val(x));
  27.         for(int i = 0; i < 16; ++i)
  28.             if(!(mask1 & (1 << i)))
  29.                 mask2 |= (1 << i);
  30.         ++f[mask1];
  31.         ans += f[mask2];
  32.     }
  33.     fout << ans;
  34. }
  35.  
Add Comment
Please, Sign In to add comment