# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1089439 | vjudge1 | Izbori (COCI17_izbori) | C++17 | 4 ms | 428 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.
/* https://oj.uz/problem/view/COCI17_izbori?locale=en: WA */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned int popcnt(unsigned int x) {
unsigned int out = 0;
while (x) {
++out;
x &= x - 1;
}
return out;
}
int main(void) {
unsigned int N, M, K, i, j, k;
unsigned int *priorities;
unsigned int *scores;
unsigned int best;
(void) scanf("%u %u %u", &N, &M, &K);
best = M - 1;
priorities = (unsigned int *) calloc(N*M, sizeof(*priorities));
scores = (unsigned int *) calloc(M, sizeof(*scores));
for (i = 0; i < N*M; ++i) {
(void) scanf(" %u", &priorities[i]);
--priorities[i];
}
for (i = 0; i < (1 << M)-1; ++i) {
memset(scores, 0, sizeof(*scores)*M);
for (j = 0; j < N; ++j) {
for (k = 0; k < M; ++k)
if (~(i & (1<<priorities[M*j+k])))
break;
++scores[priorities[M*j+k]];
}
k = 0;
for (j = 1; j < M; ++j)
if (scores[j] > scores[k])
k = j;
if (i == 0)
printf("%u\n", k + 1);
if (k == K-1 && popcnt(i) < best)
best = popcnt(i);
}
printf("%u\n", best);
return EXIT_SUCCESS;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |