Dang_Quan_10_Tin

PIN

Sep 3rd, 2021
1,505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #define task "PIN"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. using ll = long long;
  9. using ld = long double;
  10. ;
  11.  
  12. constexpr int N = 2e5 + 5;
  13. constexpr int Inf = 1e9 + 7;
  14. int n, d;
  15. int cnt[N * 10];
  16. int Pow[5], f[N];
  17.  
  18. void Read()
  19. {
  20.     cin >> n >> d;
  21.     d = 4 - d;
  22.     Pow[0] = 1;
  23.     Pow[1] = 37;
  24.     Pow[2] = 1369;
  25.     Pow[3] = 50653;
  26. }
  27.  
  28. #define Get(x) ((x >= 'a' && x <= 'z') ? (x - 'a' + 1) : (x - '0' + 1) + 26)
  29. #define bit(i, x) (((x) >> (i)) & 1)
  30.  
  31. int Val(const string &s, const int &i)
  32. {
  33.  
  34.     int ans(0);
  35.     for (int j = 0; j < 4; ++j)
  36.         if (bit(j, i))
  37.             ans += Get(s[j]) * Pow[j];
  38.     return ans;
  39. }
  40.  
  41. void Solve()
  42. {
  43.     ll ans(0);
  44.  
  45.     while (n--)
  46.     {
  47.         string s;
  48.         cin >> s;
  49.  
  50.         for (int i = 15; ~i; --i)
  51.         {
  52.             f[i] = cnt[Val(s, i)];
  53.             for (int j = i + 1; j < 16; ++j)
  54.                 if ((i & j) == i)
  55.                     f[i] -= f[j];
  56.             if (__builtin_popcount(i) == d)
  57.                 ans += f[i];
  58.         }
  59.  
  60.         for (int i = 0; i < 16; ++i)
  61.             ++cnt[Val(s, i)];
  62.     }
  63.     cout << ans;
  64. }
  65.  
  66. int32_t main()
  67. {
  68.     ios::sync_with_stdio(0);
  69.     cin.tie(0);
  70.     cout.tie(0);
  71.     if (fopen(task ".INP", "r"))
  72.     {
  73.         freopen(task ".INP", "r", stdin);
  74.         freopen(task ".OUT", "w", stdout);
  75.     }
  76.     Read();
  77.     Solve();
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment