답안 #104144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104144 2019-04-04T08:33:39 Z Kewo Izbori (COCI17_izbori) C++17
80 / 80
40 ms 512 KB
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e2 + 5);
const int M = (int)(20);
const int MASK = (int)(35000);
const int LOG = (int)(20);

int n, m, k, ar[N][M], win[MASK], on[M], ans = INT_MAX, vote[N];

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> ar[i][j];

	for(int i = 0; i <= m; i++)
		on[i] = (1 << i);

	int to = (1 << m);
	for(int mask = 0; mask < to; mask++) {
		int maxi = 0, in;
		memset(vote, 0, sizeof vote);
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				if((mask & on[ar[i][j] - 1]) == 0) {
					vote[ar[i][j]]++;
					break;
				}
			}
		}
		for(int i = 1; i <= m; i++)
			if(maxi < vote[i]) {
				maxi = vote[i];
				in = i;
			}
		win[mask] = in;
		if(win[mask] == k)
			ans = min(ans, __builtin_popcount(mask));
	}
	cout << win[0] << endl << ans;
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:60:13: warning: 'in' may be used uninitialized in this function [-Wmaybe-uninitialized]
   win[mask] = in;
   ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 10 ms 512 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 18 ms 512 KB Output is correct
13 Correct 31 ms 504 KB Output is correct
14 Correct 17 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 39 ms 492 KB Output is correct
17 Correct 18 ms 384 KB Output is correct
18 Correct 36 ms 512 KB Output is correct
19 Correct 40 ms 512 KB Output is correct
20 Correct 38 ms 504 KB Output is correct