#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
map<string, ll> cnt[16];
ll ans[5];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, d;
cin >> n >> d;
FOR(i, 0, n) {
string s;
cin >> s;
FOR(j, 0, 16) {
string sub = "";
FOR(k, 0, 4) if (j & (1 << k)) sub += s[k];
cnt[j][sub]++;
}
}
FOR(i, 0, 16) {
ll contrib = 0;
for (pair<string, ll> j : cnt[i])
contrib += j.second * (j.second - 1) / 2;
ans[4 - __builtin_popcount(i)] += contrib;
}
if (d == 1) cout << ans[1] - ans[0];
else if (d == 2) cout << ans[2] - 3 * (ans[1] - ans[0]);
else if (d == 3) cout << ans[3] - 3 * (ans[2] - 3 * (ans[1] - ans[0]));
else cout << ans[4] - ans[3] + ans[2] - ans[1] + ans[0];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1024 KB |
Output is correct |
2 |
Correct |
10 ms |
1024 KB |
Output is correct |
3 |
Correct |
9 ms |
896 KB |
Output is correct |
4 |
Correct |
72 ms |
3320 KB |
Output is correct |
5 |
Correct |
92 ms |
3704 KB |
Output is correct |
6 |
Correct |
95 ms |
3704 KB |
Output is correct |
7 |
Correct |
71 ms |
3320 KB |
Output is correct |
8 |
Correct |
97 ms |
3960 KB |
Output is correct |
9 |
Correct |
148 ms |
5240 KB |
Output is correct |
10 |
Correct |
175 ms |
5624 KB |
Output is correct |
11 |
Correct |
90 ms |
3832 KB |
Output is correct |
12 |
Incorrect |
154 ms |
5368 KB |
Output isn't correct |
13 |
Incorrect |
101 ms |
4088 KB |
Output isn't correct |
14 |
Correct |
99 ms |
3832 KB |
Output is correct |
15 |
Correct |
177 ms |
5496 KB |
Output is correct |
16 |
Correct |
226 ms |
11128 KB |
Output is correct |
17 |
Correct |
310 ms |
14584 KB |
Output is correct |
18 |
Correct |
224 ms |
12028 KB |
Output is correct |
19 |
Correct |
271 ms |
13560 KB |
Output is correct |
20 |
Correct |
314 ms |
14712 KB |
Output is correct |