#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500, MAX_K = 6;
int score[MAX_N][MAX_K];
int N, K, C;
struct Node {
bitset<MAX_N> is_forbidden, used;
int count_forced;
int best[MAX_K];
int value;
Node() {
count_forced = 0;
eval();
}
Node(Node* parent, int _count_forced) {
is_forbidden = parent->is_forbidden;
count_forced = _count_forced;
for (int i = 0; i < count_forced; i++) {
best[i] = parent->best[i];
used[best[i]] = true;
}
is_forbidden[parent->best[count_forced]] = true;
eval();
}
void eval() {
for (int event = count_forced; event < K; event++) {
best[event] = -1;
for (int i = 0; i < N; i++) {
if (!is_forbidden[i] && !used[i] && (best[event] == -1 || score[i][event] > score[best[event]][event])) {
best[event] = i;
}
}
if (best[event] == -1) {
value = INT_MIN;
return;
}
used[best[event]] = true;
}
value = 0;
for (int event = 0; event < K; event++) {
int max_score = 0;
for (int i = 0; i < K; i++) {
max_score = max(max_score, score[best[i]][event]);
}
value += max_score;
}
}
};
struct Compare {
bool operator()(Node* a, Node* b) const {
return a->value < b->value;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> N >> K >> C;
for (int i = 0; i < N; i++) {
for (int j = 0; j < K; j++) {
cin >> score[i][j];
}
}
priority_queue<Node*, vector<Node*>, Compare> pq;
pq.push(new Node());
for (int i = 0; i < C; i++) {
Node* node = pq.top();
pq.pop();
for (int count_forced = node->count_forced; count_forced < K; count_forced++) {
pq.push(new Node(node, count_forced));
}
if (i + 1 == C) {
cout << node->value << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
580 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
3 ms |
1108 KB |
Output is correct |
4 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
596 KB |
Output is correct |
3 |
Correct |
11 ms |
1244 KB |
Output is correct |
4 |
Correct |
12 ms |
1148 KB |
Output is correct |
5 |
Correct |
5 ms |
852 KB |
Output is correct |
6 |
Correct |
2 ms |
964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
2 |
Correct |
3 ms |
580 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
1108 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
3 ms |
596 KB |
Output is correct |
11 |
Correct |
11 ms |
1244 KB |
Output is correct |
12 |
Correct |
12 ms |
1148 KB |
Output is correct |
13 |
Correct |
5 ms |
852 KB |
Output is correct |
14 |
Correct |
2 ms |
964 KB |
Output is correct |
15 |
Correct |
4 ms |
908 KB |
Output is correct |
16 |
Correct |
8 ms |
1108 KB |
Output is correct |
17 |
Correct |
20 ms |
1500 KB |
Output is correct |
18 |
Correct |
8 ms |
1016 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |