답안 #1089744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089744 2024-09-17T05:24:30 Z vjudge1 Izbori (COCI17_izbori) C++17
80 / 80
18 ms 524 KB
/* 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

izbori.cpp: In function 'int main()':
izbori.cpp:29:17: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   29 |   for (i = 0; i < (1 << M)-1; ++i) {
      |               ~~^~~~~~~~~~~~
izbori.cpp:21:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   (void) scanf("%u %u %u", &N, &M, &K);
      |          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
izbori.cpp:26:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     (void) scanf(" %u", &priorities[i]);
      |            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 4 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 8 ms 348 KB Output is correct
13 Correct 13 ms 428 KB Output is correct
14 Correct 7 ms 412 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 18 ms 432 KB Output is correct
17 Correct 8 ms 348 KB Output is correct
18 Correct 15 ms 436 KB Output is correct
19 Correct 16 ms 348 KB Output is correct
20 Correct 16 ms 348 KB Output is correct