#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
using namespace std;
int N, K, C, A[509][6];
struct Node {
int a[6];
};
bool operator<(const Node &a1, const Node &a2) {
for (int i = 0; i < K; i++) {
if (a1.a[i] < a2.a[i]) return true;
if (a1.a[i] > a2.a[i]) return false;
}
return false;
}
priority_queue<pair<int, Node>>Q;
map<Node, int> Map;
int calc(Node L) {
int R[6] = { 0, 0, 0, 0, 0, 0 };
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) R[j] = max(R[j], A[L.a[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());
}
Node EE; for (int i = 0; i < K; i++) EE.a[i] = E[i];
Q.push(make_pair(calc(EE), EE));
Map[EE] = 1;
int ret = 0;
for (int i = 1; i <= C; i++) {
Node F = Q.top().second;
ret = Q.top().first; Q.pop();
vector<int> D;
for (int j = 0; j < N; j++) {
bool flag = true;
for (int k = 0; k < K; k++) {
if (F.a[k] == j) flag = false;
}
if (flag == true) D.push_back(j);
}
for (int j = 0; j < K; j++) {
for (int k : D) {
Node G = F; G.a[j] = k;
sort(G.a, G.a + K);
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 main()':
olympiads.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (E.size() == K) break;
~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
13636 KB |
Output is correct |
2 |
Correct |
358 ms |
13512 KB |
Output is correct |
3 |
Correct |
368 ms |
13636 KB |
Output is correct |
4 |
Correct |
247 ms |
3536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
10052 KB |
Output is correct |
2 |
Correct |
148 ms |
9288 KB |
Output is correct |
3 |
Correct |
164 ms |
9536 KB |
Output is correct |
4 |
Correct |
142 ms |
9164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2029 ms |
209248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
13636 KB |
Output is correct |
2 |
Correct |
358 ms |
13512 KB |
Output is correct |
3 |
Correct |
368 ms |
13636 KB |
Output is correct |
4 |
Correct |
247 ms |
3536 KB |
Output is correct |
5 |
Correct |
153 ms |
10052 KB |
Output is correct |
6 |
Correct |
148 ms |
9288 KB |
Output is correct |
7 |
Correct |
164 ms |
9536 KB |
Output is correct |
8 |
Correct |
142 ms |
9164 KB |
Output is correct |
9 |
Execution timed out |
2029 ms |
209248 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |