# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
488526 | rainboy | Set (COCI21_set) | C11 | 195 ms | 332 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 <stdio.h>
#define K 7
#define A 2187
int sub(int a, int b) {
return b == 0 ? a : sub(a / 3, b / 3) * 3 + (a % 3 - b % 3 + 3) % 3;
}
int main() {
static int cnt[A];
int n, k, i, a, b;
long long ans;
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++) {
static char cc[K + 1];
int h;
scanf("%s", cc);
a = 0;
for (h = 0; h < k; h++)
a = a * 3 + (cc[h] - '1');
cnt[a]++;
}
ans = 0;
for (a = 0; a < A; a++)
for (b = 0; b < A; b++)
ans += (long long) cnt[a] * cnt[b] * cnt[sub(sub(0, a), b)];
for (a = 0; a < A; a++) {
ans -= (long long) cnt[a] * cnt[a] * cnt[a];
ans += (long long) cnt[a] * (cnt[a] - 1) * (cnt[a] - 2);
}
ans /= 6;
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |