# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
778951 |
2023-07-11T05:06:27 Z |
이성호(#10001) |
PIN (CEOI10_pin) |
C++17 |
|
29 ms |
15100 KB |
#include <iostream>
#define int long long
using namespace std;
int cnt[37][37][37][37];
//�� ���ڿ� �ڿ����� ��������� �� digit, 0�̸� ��ü
int conv(char c)
{
if ('0' <= c && c <= '9') return c - '0' + 1;
else return c - 'a' + 11; //[1, 36]
}
signed main()
{
int N, D; cin >> N >> D;
for (int i = 1; i <= N; i++) {
char s[4]; cin >> s;
cnt[conv(s[0])][conv(s[1])][conv(s[2])][conv(s[3])]++;
}
for (int i = 36; i >= 0; i--) {
for (int j = 36; j >= 0; j--) {
for (int k = 36; k >= 0; k--) {
for (int l = (i && j && k) ? 0 : 36; l >= 0; l--) {
if (i == 0) {
for (int p = 1; p <= 36; p++) cnt[i][j][k][l] += cnt[p][j][k][l];
}
else if (j == 0) {
for (int p = 1; p <= 36; p++) cnt[i][j][k][l] += cnt[i][p][k][l];
}
else if (k == 0) {
for (int p = 1; p <= 36; p++) cnt[i][j][k][l] += cnt[i][j][p][l];
}
else if (l == 0) {
for (int p = 1; p <= 36; p++) cnt[i][j][k][l] += cnt[i][j][k][p];
}
}
}
}
}
int ans[5] = {}; //���� ���� �� ���� (���� ����)
for (int i = 1; i <= 36; i++) {
for (int j = 1; j <= 36; j++) {
for (int k = 1; k <= 36; k++) {
for (int l = 1; l <= 36; l++) {
ans[0] += cnt[i][j][k][l] * cnt[i][j][k][l];
}
}
}
}
//ans[1]: 1������ �ٸ� �� ����
for (int i = 1; i <= 36; i++) {
for (int j = 1; j <= 36; j++) {
for (int k = 1; k <= 36; k++) {
for (int l = 1; l <= 36; l++) {
if (!cnt[i][j][k][l]) continue;
ans[1] += cnt[i][j][k][l] * (cnt[0][j][k][l] + cnt[i][0][k][l] + cnt[i][j][0][l] + cnt[i][j][k][0]);
}
}
}
}
ans[1] -= 4 * ans[0];
for (int i = 1; i <= 36; i++) {
for (int j = 1; j <= 36; j++) {
for (int k = 1; k <= 36; k++) {
for (int l = 1; l <= 36; l++) {
if (!cnt[i][j][k][l]) continue;
ans[2] += cnt[i][j][k][l] * (cnt[0][0][k][l] + cnt[0][j][0][l] + cnt[0][j][k][0] + cnt[i][0][0][l] + cnt[i][0][k][0] + cnt[i][j][0][0]);
}
}
}
}
ans[2] -= (6 * ans[0] + 3 * ans[1]);
for (int i = 1; i <= 36; i++) {
for (int j = 1; j <= 36; j++) {
for (int k = 1; k <= 36; k++) {
for (int l = 1; l <= 36; l++) {
if (!cnt[i][j][k][l]) continue;
ans[3] += cnt[i][j][k][l] * (cnt[0][0][0][l] + cnt[0][0][k][0] + cnt[0][j][0][0] + cnt[i][0][0][0]);
}
}
}
}
ans[3] -= (4 * ans[0] + 3 * ans[1] + 2 * ans[2]);
ans[4] = N * N - ans[0] - ans[1] - ans[2] - ans[3];
cout << ans[D] / 2 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
14932 KB |
Output is correct |
2 |
Correct |
21 ms |
14860 KB |
Output is correct |
3 |
Correct |
27 ms |
14932 KB |
Output is correct |
4 |
Correct |
21 ms |
15048 KB |
Output is correct |
5 |
Correct |
22 ms |
15036 KB |
Output is correct |
6 |
Correct |
23 ms |
15060 KB |
Output is correct |
7 |
Correct |
27 ms |
14964 KB |
Output is correct |
8 |
Correct |
23 ms |
15060 KB |
Output is correct |
9 |
Correct |
27 ms |
15012 KB |
Output is correct |
10 |
Correct |
27 ms |
15020 KB |
Output is correct |
11 |
Correct |
24 ms |
14980 KB |
Output is correct |
12 |
Correct |
24 ms |
15100 KB |
Output is correct |
13 |
Correct |
23 ms |
15048 KB |
Output is correct |
14 |
Correct |
29 ms |
15048 KB |
Output is correct |
15 |
Correct |
26 ms |
15096 KB |
Output is correct |
16 |
Correct |
23 ms |
15020 KB |
Output is correct |
17 |
Correct |
28 ms |
15072 KB |
Output is correct |
18 |
Correct |
28 ms |
15100 KB |
Output is correct |
19 |
Correct |
28 ms |
15060 KB |
Output is correct |
20 |
Correct |
28 ms |
15084 KB |
Output is correct |