Submission #176010

# Submission time Handle Problem Language Result Execution time Memory
176010 2020-01-07T14:39:21 Z fbosnjak Izbori (COCI17_izbori) C++14
80 / 80
709 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 105;
const int maxm = 16;
int N, M, K;
int a;
int cnt[maxm];
queue <int> q[maxn];

int main()
{
	cin >> N >> M >> K;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			{cin >> a; q[i].push(a);}

	for (int i = 0; i < N; i++)
		cnt[q[i].front()]++;

	int sol;
	int ima = 0;
	for (int i = 1; i <= M; i++)
		if (cnt[i] > ima) {ima = cnt[i]; sol = i;}
	
	cout << sol << endl;

	int rj = 1e9;
	int m = (1 << M);

	for (int i = 0; i < m - 1; i++)
	{
		int curr = __builtin_popcount(i);
		queue <int> newq[N];
		for (int j = 0; j < N; j++)
			newq[j] = q[j];
		for (int j = 0; j < N; j++)
			while (((1 << (newq[j].front() - 1)) & i) == (1 << (newq[j].front() - 1))) 
				newq[j].pop();
		memset(cnt, 0, sizeof cnt);
		for (int j = 0; j < N; j++) 
			if (!newq[j].empty())
				cnt[newq[j].front()]++;
		int ima = 0;
		for (int j = 1; j <= M; j++)
			if (cnt[j] > ima) {ima = cnt[j]; sol = j;}
		if (sol == K) rj = min(rj, curr); 
	}

	cout << rj << endl;
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:26:10: warning: 'sol' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << sol << endl;
          ^~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 504 KB Output is correct
2 Correct 52 ms 376 KB Output is correct
3 Correct 21 ms 504 KB Output is correct
4 Correct 153 ms 504 KB Output is correct
5 Correct 39 ms 504 KB Output is correct
6 Correct 24 ms 504 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 83 ms 376 KB Output is correct
9 Correct 89 ms 504 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 83 ms 504 KB Output is correct
12 Correct 331 ms 504 KB Output is correct
13 Correct 641 ms 504 KB Output is correct
14 Correct 323 ms 504 KB Output is correct
15 Correct 82 ms 504 KB Output is correct
16 Correct 699 ms 504 KB Output is correct
17 Correct 341 ms 504 KB Output is correct
18 Correct 675 ms 504 KB Output is correct
19 Correct 703 ms 504 KB Output is correct
20 Correct 709 ms 504 KB Output is correct