답안 #1089439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089439 2024-09-16T13:44:44 Z vjudge1 Izbori (COCI17_izbori) C++17
42 / 80
4 ms 428 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 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 1 ms 348 KB Partially correct
3 Partially correct 0 ms 348 KB Partially correct
4 Partially correct 1 ms 348 KB Partially correct
5 Partially correct 0 ms 348 KB Partially correct
6 Partially correct 0 ms 344 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 1 ms 348 KB Partially correct
9 Partially correct 1 ms 348 KB Partially correct
10 Partially correct 0 ms 348 KB Partially correct
11 Correct 1 ms 344 KB Output is correct
12 Partially correct 2 ms 348 KB Partially correct
13 Partially correct 4 ms 348 KB Partially correct
14 Partially correct 2 ms 348 KB Partially correct
15 Partially correct 1 ms 348 KB Partially correct
16 Partially correct 4 ms 348 KB Partially correct
17 Partially correct 2 ms 348 KB Partially correct
18 Partially correct 4 ms 420 KB Partially correct
19 Partially correct 4 ms 348 KB Partially correct
20 Partially correct 4 ms 428 KB Partially correct