#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, d;
long long ans ;
string st[N] ;
map<string,long long> atm[17] ;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
cin >> n >> d ;
d = 4 - d;
for(int i = 0 ;i < n; ++ i){
cin >> st[i] ;
}
vector<int> masks ;
for(int i = 1;i < 16 ;++ i){
masks.push_back(i) ;
}
sort(masks.begin(), masks.end(), [&](int x, int y){
return __builtin_popcount(x) > __builtin_popcount(y) ;
}) ;
for(int i = 0 ;i < n; ++ i ){
long long ret = 0 ;
vector<int> dp(18, 0) ;
for(auto u : masks){
string str ;
for(int k = 0 ; k < 4 ; ++ k){
if(u&(1<<k)){
str += st[i][k] ;
}
}
dp[u] += atm[u][str]++ ;
for(int sub = u ; sub ; sub = (sub - 1) & u){
if(u != sub)
dp[sub] -= dp[u] ;
}
}
for(auto u : masks){
if(__builtin_popcount(u) == d){
ret += dp[u] ;
}
}
ans += ret ;
}
cout << ans ;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
7244 KB |
Output is correct |
2 |
Correct |
10 ms |
7116 KB |
Output is correct |
3 |
Incorrect |
9 ms |
7112 KB |
Output isn't correct |
4 |
Correct |
81 ms |
9412 KB |
Output is correct |
5 |
Correct |
78 ms |
9824 KB |
Output is correct |
6 |
Correct |
82 ms |
9868 KB |
Output is correct |
7 |
Correct |
68 ms |
9400 KB |
Output is correct |
8 |
Correct |
114 ms |
10004 KB |
Output is correct |
9 |
Correct |
146 ms |
11360 KB |
Output is correct |
10 |
Correct |
162 ms |
11736 KB |
Output is correct |
11 |
Correct |
92 ms |
9932 KB |
Output is correct |
12 |
Correct |
159 ms |
11576 KB |
Output is correct |
13 |
Correct |
98 ms |
10288 KB |
Output is correct |
14 |
Incorrect |
92 ms |
10040 KB |
Output isn't correct |
15 |
Incorrect |
153 ms |
11668 KB |
Output isn't correct |
16 |
Correct |
227 ms |
17296 KB |
Output is correct |
17 |
Correct |
281 ms |
20808 KB |
Output is correct |
18 |
Incorrect |
208 ms |
18280 KB |
Output isn't correct |
19 |
Incorrect |
257 ms |
19680 KB |
Output isn't correct |
20 |
Incorrect |
279 ms |
20796 KB |
Output isn't correct |