답안 #176002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
176002 2020-01-07T14:18:38 Z fbosnjak Izbori (COCI17_izbori) C++14
0 / 80
68 ms 65544 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 100005;
const int maxm = 20;
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; 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 ((newq[j].front() & curr) == newq[j].front()) 
				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;
          ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 68 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 62 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 63 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 62 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 62 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 63 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 62 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 62 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 63 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 66 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 62 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 61 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 63 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 63 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 68 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 63 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 61 ms 65536 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 66 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 63 ms 65544 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 63 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)