Advertisement
Dang_Quan_10_Tin

30/4/2021

Apr 5th, 2021 (edited)
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #define NguyenDangQuan the_author
  2. #define my_heart love_you_to_the_moon_and_back
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long
  6. #define ld long double
  7. #define ull unsigned long long
  8.  
  9. bool typetest;
  10. inline void fastIOfileinput()
  11. {
  12.     ios::sync_with_stdio(0);
  13.     cin.tie(0);
  14.     cout.tie(0);
  15.     typetest = 0;
  16. }
  17.  
  18. const int N = 1e5 + 5;
  19. int n, a[N], cnt[N];
  20. ll dp[17][257][257];
  21. int m, k;
  22. ll ans(0);
  23.  
  24. void Read()
  25. {
  26.     cin >> n >> m >> k;
  27.     for (int i = 1; i <= n; ++i)
  28.     {
  29.         string s;
  30.         cin >> s;
  31.         for (int j = 0; j < m; ++j)
  32.             a[i] |= (s[j] - '0') * (1 << j);
  33.     }
  34. }
  35.  
  36. void Solve()
  37. {
  38.     for (int i = 1; i < (1 << 8); ++i)
  39.         cnt[i] = __builtin_popcount(i);
  40.  
  41.     for (int i = 1; i <= n; ++i)
  42.     {
  43.         ll res = 0;
  44.  
  45.         int pref = a[i] >> 8,
  46.             suff = a[i] & ((1 << 8) - 1);
  47.  
  48.         for (int j = 0; j < (1 << 8); ++j)
  49.             if (cnt[suff ^ j] <= k)
  50.                 res += dp[k - cnt[suff ^ j]][pref][j];
  51.  
  52.         ans += res;
  53.  
  54.         for (int j = 0; j < (1 << 8); ++j)
  55.             if (cnt[pref ^ j] <= k)
  56.                 ++dp[cnt[pref ^ j]][j][suff];
  57.  
  58.         //cout << i << ": " << res << "\n";
  59.     }
  60.  
  61.     cout << ans;
  62. }
  63.  
  64. int32_t main()
  65. {
  66.     fastIOfileinput();
  67.     if (typetest)
  68.     {
  69.         int t;
  70.         cin >> t;
  71.         while (t--)
  72.         {
  73.             Read();
  74.             Solve();
  75.         }
  76.     }
  77.     else
  78.     {
  79.         Read();
  80.         Solve();
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement