답안 #1089035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089035 2024-09-15T19:28:18 Z vjudge1 Izbori (COCI17_izbori) C++17
0 / 80
41 ms 420 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;
  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]);
  for (i = 0; i < (1 << M)-1; ++i) {
    unsigned int j, k, l;
    memset(scores, 0, sizeof(*scores) * M);
    for (j = 0; j < N; ++j) {
      l = M;
      for (k = 0; k < M; ++k)
        if ((~i & (1<<k)) && (l == M || priorities[j*M+k] < priorities[j*M+l]))
          l = k;
      ++scores[l];
    }
    k = 0;
    for (j = 1; j < M; ++j)
      if (scores[j] > scores[k])
        k = j;
    if (i == 0)
      printf("%u\n", M == 1 ? 1 : k);
    if (k == K-1)
      best = popcnt(i);
  }
  printf("%u\n", best);
  return EXIT_SUCCESS;
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:27:17: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   27 |   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 Incorrect 2 ms 348 KB Output isn't correct
2 Incorrect 7 ms 416 KB Output isn't correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Incorrect 7 ms 348 KB Output isn't correct
5 Incorrect 2 ms 348 KB Output isn't correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Incorrect 9 ms 348 KB Output isn't correct
9 Incorrect 4 ms 348 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Incorrect 4 ms 344 KB Output isn't correct
12 Incorrect 17 ms 348 KB Output isn't correct
13 Incorrect 36 ms 348 KB Output isn't correct
14 Incorrect 16 ms 420 KB Output isn't correct
15 Incorrect 4 ms 420 KB Output isn't correct
16 Incorrect 41 ms 348 KB Output isn't correct
17 Incorrect 17 ms 348 KB Output isn't correct
18 Incorrect 38 ms 348 KB Output isn't correct
19 Incorrect 40 ms 348 KB Output isn't correct
20 Incorrect 40 ms 404 KB Output isn't correct