#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[6000009];
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++) {
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
219 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
216 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
216 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
219 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |