//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;
int n, d, ted[5];
map<string, int> mp;
string s[N];
ll nCr(ll x, ll y){
ll res = 1;
for (int i = 1; i <= x; i++){
res = res * i;
}
for (int i = 1; i <= y; i++) res /= i;
for (int i = 1; i <= x - y; i++) res /= i;
return res;
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> d;
d = 4 - d;
for (int i = 1; i <= n; i++){
cin >> s[i];
}
for (int i = 1; i <= n; i++){
for (int mask = 1; mask < (1 << 4); mask++){
string res = "";
int cnt = 0;
for (int j = 0; j < 4; j++){
if (mask & (1 << j)) res += s[i][j], cnt++;
else res += "?";
}
// cout << res << '\n';
ted[cnt] += mp[res];
mp[res] ++;
}
}
//cout << ted[0] << ' ' << ted[1] <
for (int i = 3; i >= 0; i--){
for (int j = i + 1; j <= 3; j++){
ted[i] -= ted[j] * nCr(j, i);
}
}
cout << ted[d];
return 0;
}
Compilation message
pin.cpp:8:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
#pragma GCC optimise ("ofast")
pin.cpp:9:0: warning: ignoring #pragma GCC optimise [-Wunknown-pragmas]
#pragma GCC optimise("unroll-loops")
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
7288 KB |
Output is correct |
2 |
Correct |
20 ms |
7288 KB |
Output is correct |
3 |
Incorrect |
17 ms |
7160 KB |
Output isn't correct |
4 |
Correct |
152 ms |
9592 KB |
Output is correct |
5 |
Correct |
191 ms |
9980 KB |
Output is correct |
6 |
Correct |
196 ms |
9976 KB |
Output is correct |
7 |
Correct |
153 ms |
9596 KB |
Output is correct |
8 |
Correct |
209 ms |
10276 KB |
Output is correct |
9 |
Correct |
343 ms |
11576 KB |
Output is correct |
10 |
Correct |
381 ms |
12024 KB |
Output is correct |
11 |
Correct |
202 ms |
10052 KB |
Output is correct |
12 |
Correct |
362 ms |
11640 KB |
Output is correct |
13 |
Correct |
234 ms |
10496 KB |
Output is correct |
14 |
Incorrect |
212 ms |
10104 KB |
Output isn't correct |
15 |
Incorrect |
363 ms |
11768 KB |
Output isn't correct |
16 |
Correct |
353 ms |
17384 KB |
Output is correct |
17 |
Correct |
539 ms |
20856 KB |
Output is correct |
18 |
Incorrect |
403 ms |
18296 KB |
Output isn't correct |
19 |
Incorrect |
481 ms |
19788 KB |
Output isn't correct |
20 |
Incorrect |
531 ms |
20856 KB |
Output isn't correct |