#include <bits/stdc++.h>
using namespace std;
struct node
{
vector<bool> forbidden;
vector<int> forced, team;
int score;
};
inline bool operator<(const node &a, const node &b) { return a.score < b.score; }
int n, k, c, t[505][6];
void finish_team(node &no)
{
no.team = no.forced;
for (int i = no.team.size(); i < k; i++)
{
no.team.push_back(-1);
for (int j = 0; j < n; j++)
if (!no.forbidden[j] && !count(no.team.begin(), no.team.end(), j) && (no.team.back() == -1 || t[j][i] > t[no.team.back()][i]))
no.team.back() = j;
}
no.score = 0;
for (int i = 0; i < k; i++)
{
int maxi = 0;
for (int j : no.team) maxi = max(maxi, t[j][i]);
no.score += maxi;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> c;
for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> t[i][j];
node st = {vector<bool>(n, false), {}, {}, 0};
finish_team(st);
priority_queue<node> pq;
pq.push(st);
for (int i = 0; i < c; i++)
{
node no = pq.top(); pq.pop();
//cout << no.score << endl;
if (i == c-1)
{
cout << no.score << "\n";
return 0;
}
for (int i = no.forced.size(); i < k; i++)
{
node nw = no;
nw.team.clear();
nw.forbidden[no.team[i]] = true;
finish_team(nw);
if (!count(nw.team.begin(), nw.team.end(), -1))
pq.push(nw);
no.forced.push_back(no.team[i]);
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
7 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
588 KB |
Output is correct |
2 |
Correct |
4 ms |
332 KB |
Output is correct |
3 |
Correct |
8 ms |
812 KB |
Output is correct |
4 |
Correct |
6 ms |
572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
332 KB |
Output is correct |
2 |
Correct |
7 ms |
240 KB |
Output is correct |
3 |
Correct |
43 ms |
1020 KB |
Output is correct |
4 |
Correct |
51 ms |
1012 KB |
Output is correct |
5 |
Correct |
15 ms |
444 KB |
Output is correct |
6 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
332 KB |
Output is correct |
2 |
Correct |
7 ms |
332 KB |
Output is correct |
3 |
Correct |
6 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
588 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
8 ms |
812 KB |
Output is correct |
8 |
Correct |
6 ms |
572 KB |
Output is correct |
9 |
Correct |
10 ms |
332 KB |
Output is correct |
10 |
Correct |
7 ms |
240 KB |
Output is correct |
11 |
Correct |
43 ms |
1020 KB |
Output is correct |
12 |
Correct |
51 ms |
1012 KB |
Output is correct |
13 |
Correct |
15 ms |
444 KB |
Output is correct |
14 |
Correct |
5 ms |
588 KB |
Output is correct |
15 |
Correct |
15 ms |
448 KB |
Output is correct |
16 |
Correct |
30 ms |
976 KB |
Output is correct |
17 |
Correct |
68 ms |
1668 KB |
Output is correct |
18 |
Correct |
31 ms |
788 KB |
Output is correct |
19 |
Correct |
7 ms |
360 KB |
Output is correct |