답안 #133255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
133255 2019-07-20T10:04:52 Z E869120 Olympiads (BOI19_olympiads) C++14
0 / 100
2000 ms 213428 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
using namespace std;

int N, K, C, A[509][6];
queue<vector<int>> Q[69];
map<vector<int>, int> Map;

int calc(vector<int> L) {
	int R[6] = { 0, 0, 0, 0, 0, 0 };
	for (int i = 0; i < L.size(); i++) {
		for (int j = 0; j < K; j++) R[j] = max(R[j], A[L[i]][j]);
	}
	int sum = 0;
	for (int i = 0; i < K; i++) sum += R[i];
	return sum;
}

int main() {
	cin >> N >> K >> C;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < K; j++) cin >> A[i][j];
	}

	vector<int>E;
	for (int i = 0; i < K; i++) {
		int maxn = -1, maxid = -1;
		for (int j = 0; j < N; j++) {
			if (maxn < A[j][i]) { maxn = A[j][i]; maxid = j; }
		}
		E.push_back(maxid);
	}
	sort(E.begin(), E.end());
	E.erase(unique(E.begin(), E.end()), E.end());
	for (int i = 0; i < N; i++) {
		if (E.size() == K) break;
		E.push_back(i);
		sort(E.begin(), E.end());
		E.erase(unique(E.begin(), E.end()), E.end());
	}

	Q[calc(E)].push(E);
	Map[E] = 1;
	int MAX = calc(E), ret = 0, cnt = 0;

	for (int i = MAX; i >= 0; i--) {
		while (!Q[i].empty()) {
			vector<int> F = Q[i].front();
			ret = calc(F); Q[i].pop(); cnt++;
			if (cnt == C) break;

			vector<int> D;
			for (int j = 0; j < N; j++) {
				bool flag = true;
				for (int k = 0; k < F.size(); k++) {
					if (F[k] == j) flag = false;
				}
				if (flag == true) D.push_back(j);
			}

			for (int j = 0; j < F.size(); j++) {
				for (int k : D) {
					vector<int> G = F; G[j] = k;
					sort(G.begin(), G.end());
					if (Map[G] == 1) continue;

					Map[G] = 1;
					int Z = calc(G);
					Q[Z].push(G);
				}
			}
		}
		if (cnt == C) break;
	}
	cout << ret << endl;
	return 0;
}

Compilation message

olympiads.cpp: In function 'int calc(std::vector<int>)':
olympiads.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < L.size(); i++) {
                  ~~^~~~~~~~~~
olympiads.cpp: In function 'int main()':
olympiads.cpp:40:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (E.size() == K) break;
       ~~~~~~~~~^~~~
olympiads.cpp:59:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int k = 0; k < F.size(); k++) {
                     ~~^~~~~~~~~~
olympiads.cpp:65:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < F.size(); j++) {
                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2070 ms 213428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -