Submission #40400

# Submission time Handle Problem Language Result Execution time Memory
40400 2018-01-31T13:18:23 Z szawinis Izbori (COCI17_izbori) C++14
80 / 80
33 ms 776 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 101, M = 16;

int n, m, k, ans = INT_MAX, a[N][M], cnt[M];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) cin >> a[i][j];
		++cnt[a[i][1]];
	}
	cout << max_element(cnt+1, cnt+m+1) - cnt << endl;
	for(int mask = 0; mask < (1 << m) - 1; mask++) {
		fill(cnt+1, cnt+m+1, 0);
		for(int i = 1; i <= n; i++) {
			int j = 1;
			while(mask >> (a[i][j] - 1) & 1) ++j;
			++cnt[a[i][j]];
		}
		if(max_element(cnt+1, cnt+m+1) - cnt == k) ans = min(__builtin_popcount(mask), ans);
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 464 KB Output is correct
4 Correct 8 ms 484 KB Output is correct
5 Correct 3 ms 524 KB Output is correct
6 Correct 3 ms 528 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 4 ms 536 KB Output is correct
9 Correct 5 ms 540 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 5 ms 636 KB Output is correct
12 Correct 14 ms 644 KB Output is correct
13 Correct 33 ms 664 KB Output is correct
14 Correct 13 ms 668 KB Output is correct
15 Correct 5 ms 672 KB Output is correct
16 Correct 29 ms 676 KB Output is correct
17 Correct 16 ms 680 KB Output is correct
18 Correct 27 ms 768 KB Output is correct
19 Correct 28 ms 772 KB Output is correct
20 Correct 29 ms 776 KB Output is correct