#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<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.push(make_pair(calc(E), E));
Map[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;
if (Map[G] == 1) continue;
Map[G] = 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 'int main()':
olympiads.cpp:40:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (E.size() == K) break;
~~~~~~~~~^~~~
olympiads.cpp:54:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < F.size(); j++) {
~~^~~~~~~~~~
olympiads.cpp:59:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (G.size() != K) continue;
~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
564 ms |
21864 KB |
Output is correct |
2 |
Correct |
566 ms |
21860 KB |
Output is correct |
3 |
Correct |
573 ms |
21848 KB |
Output is correct |
4 |
Correct |
437 ms |
5636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
241 ms |
16096 KB |
Output is correct |
2 |
Correct |
230 ms |
13800 KB |
Output is correct |
3 |
Correct |
257 ms |
15076 KB |
Output is correct |
4 |
Correct |
220 ms |
13796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2065 ms |
249324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
564 ms |
21864 KB |
Output is correct |
2 |
Correct |
566 ms |
21860 KB |
Output is correct |
3 |
Correct |
573 ms |
21848 KB |
Output is correct |
4 |
Correct |
437 ms |
5636 KB |
Output is correct |
5 |
Correct |
241 ms |
16096 KB |
Output is correct |
6 |
Correct |
230 ms |
13800 KB |
Output is correct |
7 |
Correct |
257 ms |
15076 KB |
Output is correct |
8 |
Correct |
220 ms |
13796 KB |
Output is correct |
9 |
Execution timed out |
2065 ms |
249324 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |