Submission #44573

# Submission time Handle Problem Language Result Execution time Memory
44573 2018-04-03T11:49:45 Z heon Izbori (COCI17_izbori) C++11
80 / 80
34 ms 560 KB
#include<bits/stdc++.h>

using namespace std;

int n,m,k;
int grid[105][15];

int winner(int mask){
	int winner[20];
	memset(winner,0,sizeof(winner));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(mask & (1 << (grid[i][j]-1))) continue;
			winner[grid[i][j]]++;
			break;
		}
	}
	int winval = 0, win;
	for(int i = 1; i <= m; i++){
		if(winner[i] > winval){
			winval = winner[i];
			win = i;
		}
	}
	return win;
}

int main(){
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> grid[i][j]; 
		}
	}
	int izbaceni = 10000;
	int fullmask = 1 << m;
	for(int i = 0; i < fullmask-1; i++){
		if(winner(i) == k){
			izbaceni = min(izbaceni,__builtin_popcount(i));
		}
	}
	cout << winner(0) << endl << izbaceni;
}

Compilation message

izbori.cpp: In function 'int winner(int)':
izbori.cpp:25:9: warning: 'win' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return win;
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 248 KB Output is correct
2 Correct 4 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 10 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 4 ms 544 KB Output is correct
9 Correct 6 ms 544 KB Output is correct
10 Correct 2 ms 544 KB Output is correct
11 Correct 5 ms 544 KB Output is correct
12 Correct 16 ms 544 KB Output is correct
13 Correct 29 ms 560 KB Output is correct
14 Correct 15 ms 560 KB Output is correct
15 Correct 6 ms 560 KB Output is correct
16 Correct 34 ms 560 KB Output is correct
17 Correct 16 ms 560 KB Output is correct
18 Correct 30 ms 560 KB Output is correct
19 Correct 34 ms 560 KB Output is correct
20 Correct 33 ms 560 KB Output is correct