Submission #471725

#TimeUsernameProblemLanguageResultExecution timeMemory
471725rainboyIzbori (COCI17_izbori)C11
80 / 80
18 ms2340 KiB
#include <stdio.h> #define N 15 int max(int a, int b) { return a > b ? a : b; } int main() { static int kk[1 << N][N], cnt[1 << N]; int n, m, i_, i, b, ans; scanf("%d%d%d", &m, &n, &i_), i_--; while (m--) { static int pp[N]; for (i = 0; i < n; i++) scanf("%d", &pp[i]), pp[i]--; for (b = 1; b < 1 << n; b++) for (i = 0; i < n; i++) if ((b & 1 << pp[i]) != 0) { kk[b][pp[i]]++; break; } } for (b = 1; b < 1 << n; b++) cnt[b] = cnt[b & b - 1] + 1; ans = 0; for (b = 1; b < 1 << n; b++) if ((b & 1 << i_) != 0) { int win = 1; for (i = 0; i < n; i++) if (i != i_ && kk[b][i_] < kk[b][i] || kk[b][i_] == kk[b][i] && i_ > i) { win = 0; break; } if (win) ans = max(ans, cnt[b]); } ans = n - ans; i_ = -1; for (i = 0; i < n; i++) if (i_ == -1 || kk[(1 << n) - 1][i_] < kk[(1 << n) - 1][i]) i_ = i; printf("%d\n", i_ + 1); printf("%d\n", ans); return 0; }

Compilation message (stderr)

izbori.c: In function 'main':
izbori.c:25:22: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   25 |   cnt[b] = cnt[b & b - 1] + 1;
      |                    ~~^~~
izbori.c:32:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   32 |     if (i != i_ && kk[b][i_] < kk[b][i] || kk[b][i_] == kk[b][i] && i_ > i) {
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
izbori.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d%d", &m, &n, &i_), i_--;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
izbori.c:16:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |    scanf("%d", &pp[i]), pp[i]--;
      |    ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...