# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
788422 | math_rabbit_1028 | PIN (CEOI10_pin) | C++14 | 66 ms | 28120 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
long long n, d, arr[36][36][36][36];
long long zero, one[36][4], two[36][36][6], three[36][36][36][4], four[36][36][36][36];
int CharToInt(char c) {
if (c <= '9') return c - '0';
if (c >= 'a') return c - 'a' + 10;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> d;
for (int i = 1; i <= n; i++) {
char s[10];
cin >> s;
arr[CharToInt(s[0])][CharToInt(s[1])][CharToInt(s[2])][CharToInt(s[3])] = 1;
}
for (int i = 0; i < 36; i++) {
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
four[i][j][k][l] = arr[i][j][k][l] * (arr[i][j][k][l] + 1) / 2;
}
}
}
}
for (int i = 0; i < 36; i++) {
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
three[i][j][k][0] += arr[i][j][k][l];
three[i][j][k][1] += arr[i][j][l][k];
three[i][j][k][2] += arr[i][l][j][k];
three[i][j][k][3] += arr[l][i][j][k];
}
three[i][j][k][0] = three[i][j][k][0] * (three[i][j][k][0] + 1) / 2;
three[i][j][k][1] = three[i][j][k][1] * (three[i][j][k][1] + 1) / 2;
three[i][j][k][2] = three[i][j][k][2] * (three[i][j][k][2] + 1) / 2;
three[i][j][k][3] = three[i][j][k][3] * (three[i][j][k][3] + 1) / 2;
for (int l = 0; l < 36; l++) {
three[i][j][k][0] -= four[i][j][k][l];
three[i][j][k][1] -= four[i][j][l][k];
three[i][j][k][2] -= four[i][l][j][k];
three[i][j][k][3] -= four[l][i][j][k];
}
}
}
}
for (int i = 0; i < 36; i++) {
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
two[i][j][0] += arr[i][j][k][l];
two[i][j][1] += arr[i][k][j][l];
two[i][j][2] += arr[i][k][l][j];
two[i][j][3] += arr[k][i][j][l];
two[i][j][4] += arr[k][i][l][j];
two[i][j][5] += arr[k][l][i][j];
}
}
two[i][j][0] = two[i][j][0] * (two[i][j][0] + 1) / 2;
two[i][j][1] = two[i][j][1] * (two[i][j][1] + 1) / 2;
two[i][j][2] = two[i][j][2] * (two[i][j][2] + 1) / 2;
two[i][j][3] = two[i][j][3] * (two[i][j][3] + 1) / 2;
two[i][j][4] = two[i][j][4] * (two[i][j][4] + 1) / 2;
two[i][j][5] = two[i][j][5] * (two[i][j][5] + 1) / 2;
for (int k = 0; k < 36; k++) {
two[i][j][0] -= three[i][j][k][0];
two[i][j][1] -= three[i][k][j][0];
two[i][j][2] -= three[i][k][j][1];
two[i][j][3] -= three[k][i][j][0];
two[i][j][4] -= three[k][i][j][1];
two[i][j][5] -= three[k][i][j][2];
}
for (int l = 0; l < 36; l++) {
two[i][j][0] -= three[i][j][l][1];
two[i][j][1] -= three[i][j][l][2];
two[i][j][2] -= three[i][l][j][2];
two[i][j][3] -= three[i][j][l][3];
two[i][j][4] -= three[i][l][j][3];
two[i][j][5] -= three[l][i][j][3];
}
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
two[i][j][0] -= four[i][j][k][l];
two[i][j][1] -= four[i][k][j][l];
two[i][j][2] -= four[i][k][l][j];
two[i][j][3] -= four[k][i][j][l];
two[i][j][4] -= four[k][i][l][j];
two[i][j][5] -= four[k][l][i][j];
}
}
}
}
for (int i = 0; i < 36; i++) {
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
one[i][0] += arr[i][j][k][l];
one[i][1] += arr[j][i][k][l];
one[i][2] += arr[j][k][i][l];
one[i][3] += arr[j][k][l][i];
}
}
}
one[i][0] = one[i][0] * (one[i][0] + 1) / 2;
one[i][1] = one[i][1] * (one[i][1] + 1) / 2;
one[i][2] = one[i][2] * (one[i][2] + 1) / 2;
one[i][3] = one[i][3] * (one[i][3] + 1) / 2;
for (int j = 0; j < 36; j++) {
one[i][0] -= two[i][j][0];
one[i][1] -= two[j][i][0];
one[i][2] -= two[j][i][1];
one[i][3] -= two[j][i][2];
}
for (int k = 0; k < 36; k++) {
one[i][0] -= two[i][k][1];
one[i][1] -= two[i][k][3];
one[i][2] -= two[k][i][3];
one[i][3] -= two[k][i][4];
}
for (int l = 0; l < 36; l++) {
one[i][0] -= two[i][l][2];
one[i][1] -= two[i][l][4];
one[i][2] -= two[i][l][5];
one[i][3] -= two[l][i][5];
}
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
one[i][0] -= three[i][j][k][0];
one[i][1] -= three[j][i][k][0];
one[i][2] -= three[j][k][i][0];
one[i][3] -= three[j][k][i][1];
}
}
for (int j = 0; j < 36; j++) {
for (int l = 0; l < 36; l++) {
one[i][0] -= three[i][j][l][1];
one[i][1] -= three[j][i][l][1];
one[i][2] -= three[j][i][l][2];
one[i][3] -= three[j][l][i][2];
}
}
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
one[i][0] -= three[i][k][l][2];
one[i][1] -= three[i][k][l][3];
one[i][2] -= three[k][i][l][3];
one[i][3] -= three[k][l][i][3];
}
}
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
for (int l = 0; l < 36; l++) {
one[i][0] -= four[i][j][k][l];
one[i][1] -= four[j][i][k][l];
one[i][2] -= four[j][k][i][l];
one[i][3] -= four[j][k][l][i];
}
}
}
}
long long three_tot = 0, two_tot = 0, one_tot = 0, zero_tot = n * (n - 1) / 2;
for (int i = 0; i < 36; i++) {
for (int j = 0; j < 36; j++) {
for (int k = 0; k < 36; k++) {
three_tot += three[i][j][k][0];
three_tot += three[i][j][k][1];
three_tot += three[i][j][k][2];
three_tot += three[i][j][k][3];
}
}
}
for (int i = 0; i < 36; i++) {
for (int j = 0; j < 36; j++) {
two_tot += two[i][j][0];
two_tot += two[i][j][1];
two_tot += two[i][j][2];
two_tot += two[i][j][3];
two_tot += two[i][j][4];
two_tot += two[i][j][5];
}
}
for (int i = 0; i < 36; i++) {
one_tot += one[i][0];
one_tot += one[i][1];
one_tot += one[i][2];
one_tot += one[i][3];
}
zero_tot = zero_tot - one_tot - two_tot - three_tot;
if (d == 1) cout << three_tot << "\n";
if (d == 2) cout << two_tot << "\n";
if (d == 3) cout << one_tot << "\n";
if (d == 4) cout << zero_tot << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |