답안 #133248

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

int N, K, C, A[509][6];
priority_queue<pair<int, vector<int>>>Q;
map<long long, 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;
}

long long hash_val(vector<int> &T) {
	long long r = 0;
	for (int i = 0; i < T.size(); i++) r += ((long long)T[i] << (10 * i));
	return r;
}

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.push(make_pair(calc(E), E));
	Map[hash_val(E)] = 1;

	int ret = 0;
	for (int i = 1; i <= C; i++) {
		vector<int> F = Q.top().second;
		ret = Q.top().first; Q.pop();

		for (int j = 0; j < F.size(); j++) {
			for (int k = 0; k < N; k++) {
				vector<int> G = F; G[j] = k;
				sort(G.begin(), G.end());
				G.erase(unique(G.begin(), G.end()), G.end());
				if (G.size() != K) continue;

				long long e = hash_val(G);
				if (Map[e] == 1) continue;

				Map[e] = 1;
				int Z = calc(G);
				Q.push(make_pair(Z, G));
			}
		}
	}
	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 'long long int hash_val(std::vector<int>&)':
olympiads.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < T.size(); i++) r += ((long long)T[i] << (10 * i));
                  ~~^~~~~~~~~~
olympiads.cpp: In function 'int main()':
olympiads.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (E.size() == K) break;
       ~~~~~~~~~^~~~
olympiads.cpp:60:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < F.size(); j++) {
                   ~~^~~~~~~~~~
olympiads.cpp:65:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (G.size() != K) continue;
         ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 665 ms 16092 KB Output is correct
2 Correct 472 ms 16072 KB Output is correct
3 Correct 594 ms 15968 KB Output is correct
4 Correct 306 ms 4048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 11740 KB Output is correct
2 Correct 162 ms 10720 KB Output is correct
3 Correct 183 ms 11100 KB Output is correct
4 Correct 183 ms 10708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2099 ms 259096 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 665 ms 16092 KB Output is correct
2 Correct 472 ms 16072 KB Output is correct
3 Correct 594 ms 15968 KB Output is correct
4 Correct 306 ms 4048 KB Output is correct
5 Correct 179 ms 11740 KB Output is correct
6 Correct 162 ms 10720 KB Output is correct
7 Correct 183 ms 11100 KB Output is correct
8 Correct 183 ms 10708 KB Output is correct
9 Execution timed out 2099 ms 259096 KB Time limit exceeded
10 Halted 0 ms 0 KB -