#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 1000005
#define int long long
int temp[4], same[4];
int cnt[40][40][40][40];
int get(char ch) {
if (ch >= '0' && ch <= '9')
return ch-'0';
return ch-'a'+10;
}
signed main() {
fast
int N, D;
cin >> N >> D;
vector<string> PIN(N);
for (int i = 0; i < N; i++) {
cin >> PIN[i];
for (int mask = 0; mask < 16; mask++) {
for (int plc = 0; plc < 4; plc++) {
if ((1<<plc) & mask)
temp[plc] = get(PIN[i][plc]);
else
temp[plc] = 36;
}
cnt[temp[0]][temp[1]][temp[2]][temp[3]]++;
}
}
for (int plc1 = 0; plc1 <= 36; plc1++) {
for (int plc2 = 0; plc2 <= 36; plc2++) {
for (int plc3 = 0; plc3 <= 36; plc3++) {
for (int plc4 = 0; plc4 <= 36; plc4++) {
int same_plc = (plc1 < 36) + (plc2 < 36) + (plc3 < 36) + (plc4 < 36);
same[same_plc] += (cnt[plc1][plc2][plc3][plc4] * (cnt[plc1][plc2][plc3][plc4] - 1)) / 2;
}
}
}
}
if (D == 1)
cout << same[3] << "\n";
else if (D == 2)
cout << same[2] - 3 * same[3] << "\n";
else if (D == 3)
cout << same[1] - 2 * same[2] + 3 * same[3] << "\n";
else
cout << same[0] - same[1] + same[2] - same[3] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3284 KB |
Output is correct |
2 |
Correct |
7 ms |
3316 KB |
Output is correct |
3 |
Correct |
7 ms |
3156 KB |
Output is correct |
4 |
Correct |
14 ms |
4056 KB |
Output is correct |
5 |
Correct |
11 ms |
4200 KB |
Output is correct |
6 |
Correct |
11 ms |
4180 KB |
Output is correct |
7 |
Correct |
11 ms |
4052 KB |
Output is correct |
8 |
Correct |
12 ms |
4272 KB |
Output is correct |
9 |
Correct |
15 ms |
4820 KB |
Output is correct |
10 |
Correct |
16 ms |
4968 KB |
Output is correct |
11 |
Correct |
11 ms |
4180 KB |
Output is correct |
12 |
Correct |
15 ms |
4884 KB |
Output is correct |
13 |
Correct |
13 ms |
4352 KB |
Output is correct |
14 |
Correct |
12 ms |
4268 KB |
Output is correct |
15 |
Correct |
16 ms |
4820 KB |
Output is correct |
16 |
Correct |
21 ms |
18564 KB |
Output is correct |
17 |
Correct |
27 ms |
19084 KB |
Output is correct |
18 |
Correct |
23 ms |
18712 KB |
Output is correct |
19 |
Correct |
24 ms |
18900 KB |
Output is correct |
20 |
Correct |
26 ms |
19028 KB |
Output is correct |