Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "PIN"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- ;
- constexpr int N = 2e5 + 5;
- constexpr int Inf = 1e9 + 7;
- int n, d;
- int cnt[N * 10];
- int Pow[5], f[N];
- void Read()
- {
- cin >> n >> d;
- d = 4 - d;
- Pow[0] = 1;
- Pow[1] = 37;
- Pow[2] = 1369;
- Pow[3] = 50653;
- }
- #define Get(x) ((x >= 'a' && x <= 'z') ? (x - 'a' + 1) : (x - '0' + 1) + 26)
- #define bit(i, x) (((x) >> (i)) & 1)
- int Val(const string &s, const int &i)
- {
- int ans(0);
- for (int j = 0; j < 4; ++j)
- if (bit(j, i))
- ans += Get(s[j]) * Pow[j];
- return ans;
- }
- void Solve()
- {
- ll ans(0);
- while (n--)
- {
- string s;
- cin >> s;
- for (int i = 15; ~i; --i)
- {
- f[i] = cnt[Val(s, i)];
- for (int j = i + 1; j < 16; ++j)
- if ((i & j) == i)
- f[i] -= f[j];
- if (__builtin_popcount(i) == d)
- ans += f[i];
- }
- for (int i = 0; i < 16; ++i)
- ++cnt[Val(s, i)];
- }
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment