답안 #198597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198597 2020-01-26T18:40:24 Z ZwariowanyMarcin Izbori (COCI17_izbori) C++14
80 / 80
23 ms 504 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define ld long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);


using namespace std;		

const int nax = 110;

int n, m, k;
int a[nax][nax];
int points[nax];

int alive[nax];

int main() {
	scanf ("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j)
			scanf ("%d", &a[i][j]);
		points[a[i][1]]++;
	}
	
	pair <int, int> winner = {-1, 0};
	for (int i = 1; i <= m; ++i)
		winner = max(winner, {points[i], -i});
	printf ("%d\n", -1 * winner.se);
	
	int ans = m - 1;
	for (int mask = 0; mask < (1 << m) - 1; ++mask) {
		if ((mask >> (k - 1)) & 1) continue;
		for (int i = 0; i < m; ++i) {
			alive[i + 1] = !((mask >> i) & 1);
			points[i + 1] = 0;
		}
		
		for (int i = 1; i <= n; ++i) {
			int j = 1;
			while (!alive[a[i][j]]) j++;
			points[a[i][j]]++;
		}
		
		pair <int, int> winner = {-1, 0};
		for (int i = 1; i <= m; ++i)
			winner = max(winner, {points[i], -i});
		if (winner.se == -k)
			ans = min(ans, __builtin_popcount(mask));
	}
	
	printf ("%d", ans);
		
	
	return 0;
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d%d", &n, &m, &k);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
izbori.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d", &a[i][j]);
    ~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 256 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 7 ms 376 KB Output is correct
12 Correct 12 ms 376 KB Output is correct
13 Correct 19 ms 376 KB Output is correct
14 Correct 13 ms 376 KB Output is correct
15 Correct 7 ms 376 KB Output is correct
16 Correct 23 ms 376 KB Output is correct
17 Correct 13 ms 376 KB Output is correct
18 Correct 21 ms 504 KB Output is correct
19 Correct 22 ms 376 KB Output is correct
20 Correct 22 ms 376 KB Output is correct