#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int K = 4;
const int N = 5e4+1;
map<string, ll> mp[(1<<K)];
ll ans[6], n, d;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>d;
for (int i=1; i<=n; ++i) {
string s; cin>>s;
for (int j=1; j<(1<<K); ++j) {
string tmp;
for (int x=0; x<K; ++x) {
if (j&(1<<x)) tmp+=s[x];
}
++mp[j][tmp];
}
}
for (int m=0; m<(1<<K); ++m) {
ll tmp=0;
for (auto u : mp[m]) tmp+=u.second*(u.second-1)/2;
ans[4-__builtin_popcount(m)]+=tmp;
}
ll k;
if (d == 1) k=ans[1]-ans[0];
else if (d == 2) k=ans[2]-3*(ans[1]-ans[0]);
else if (d == 3) k=ans[3]-2*ans[2]+3*(ans[1]-ans[0]);
else k=ans[4]-ans[3]+ans[2]-ans[1]+ans[0];
k=max(0ll, k);
cout<<k<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
980 KB |
Output is correct |
2 |
Correct |
5 ms |
852 KB |
Output is correct |
3 |
Incorrect |
4 ms |
852 KB |
Output isn't correct |
4 |
Correct |
54 ms |
3232 KB |
Output is correct |
5 |
Correct |
62 ms |
3572 KB |
Output is correct |
6 |
Correct |
64 ms |
3592 KB |
Output is correct |
7 |
Correct |
51 ms |
3184 KB |
Output is correct |
8 |
Correct |
75 ms |
3764 KB |
Output is correct |
9 |
Correct |
115 ms |
5180 KB |
Output is correct |
10 |
Correct |
132 ms |
5684 KB |
Output is correct |
11 |
Correct |
69 ms |
3760 KB |
Output is correct |
12 |
Correct |
123 ms |
5324 KB |
Output is correct |
13 |
Correct |
78 ms |
3976 KB |
Output is correct |
14 |
Incorrect |
70 ms |
3816 KB |
Output isn't correct |
15 |
Incorrect |
140 ms |
5356 KB |
Output isn't correct |
16 |
Correct |
167 ms |
11036 KB |
Output is correct |
17 |
Correct |
259 ms |
14484 KB |
Output is correct |
18 |
Incorrect |
185 ms |
12236 KB |
Output isn't correct |
19 |
Incorrect |
223 ms |
13376 KB |
Output isn't correct |
20 |
Incorrect |
244 ms |
14468 KB |
Output isn't correct |