#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
const ll Mod = 1000000007LL;
const int N = 5e4 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;
map<str, int> mp;
str s[N];
int cnt[5];
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, d;
cin >> n >> d;
for(int i = 1; i <= n; i++) cin >> s[i];
str t;
for(int mk = 0; mk < 15; mk++){
mp.clear();
for(int i = 1; i <= n; i++){
t = "";
for(int j = 0; j < 4; j++){
if(mk >> j & 1) t += s[i][j];
else t += '?';
}
cnt[__builtin_popcount(mk)] += mp[t];
mp[t] ++;
}
}
cnt[2] -= cnt[3] * 3;
cnt[1] -= cnt[3] * 3;
cnt[1] -= cnt[2] * 2;
cnt[0] -= cnt[1] + cnt[2] + cnt[3];
cout << cnt[4 - d] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1912 KB |
Output is correct |
2 |
Correct |
12 ms |
2040 KB |
Output is correct |
3 |
Correct |
11 ms |
2040 KB |
Output is correct |
4 |
Correct |
83 ms |
2296 KB |
Output is correct |
5 |
Correct |
108 ms |
2296 KB |
Output is correct |
6 |
Correct |
101 ms |
2424 KB |
Output is correct |
7 |
Correct |
85 ms |
2364 KB |
Output is correct |
8 |
Correct |
110 ms |
2296 KB |
Output is correct |
9 |
Correct |
175 ms |
2556 KB |
Output is correct |
10 |
Correct |
192 ms |
2556 KB |
Output is correct |
11 |
Correct |
112 ms |
2296 KB |
Output is correct |
12 |
Correct |
182 ms |
2596 KB |
Output is correct |
13 |
Correct |
118 ms |
2296 KB |
Output is correct |
14 |
Correct |
110 ms |
2296 KB |
Output is correct |
15 |
Correct |
185 ms |
2424 KB |
Output is correct |
16 |
Correct |
183 ms |
3960 KB |
Output is correct |
17 |
Correct |
266 ms |
4600 KB |
Output is correct |
18 |
Correct |
203 ms |
4088 KB |
Output is correct |
19 |
Correct |
240 ms |
4344 KB |
Output is correct |
20 |
Correct |
267 ms |
4600 KB |
Output is correct |