#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 505;
const int mod = 1e9 + 7;
int n, k, c, arr[maxn][6];
struct shard
{
int score;
vector<int>choices, team;
shard()
{
score = 0;
choices = vector<int>(maxn, 0);
}
bool operator<(const shard &o) const
{
return score < o.score;
}
};
shard null()
{
shard a;
a.score = -1;
return a;
}
shard eval(shard a)
{
vector<int>new_team;
for(int i : a.team)
if(a.choices[i] == 1)
new_team.pb(i);
for(int j = sz(new_team); j < k; j++)
{
int id = -1;
for(int i = 0; i < n; i++)
{
if(!count(all(new_team), i) && a.choices[i] != -1)
{
if(id == -1 || arr[i][j] > arr[id][j])
id = i;
}
}
if(id == -1) return null();
new_team.pb(id);
}
a.team = new_team;
a.score = 0;
for(int j = 0; j < k; j++)
{
int add = 0;
for(int i : a.team)
add = max(add, arr[i][j]);
a.score += add;
}
return a;
}
int main()
{
ios_base::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 >> arr[i][j];
shard st = eval(shard());
priority_queue<shard>Q;
Q.push(st);
for(int i = 1; i <= c; i++)
{
shard a = Q.top();
Q.pop();
if(i == c)
{
cout << a.score << "\n";
return 0;
}
for(int j = 0; j < k; j++)
{
if(a.choices[a.team[j]] == 0)
{
shard b = a;
b.choices[b.team[j]] = -1;
for(int jj = 0; jj < j; jj++)
b.choices[b.team[jj]] = 1;
b = eval(b);
if(b.score != -1) Q.push(b);
}
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
504 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
9 ms |
504 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3192 KB |
Output is correct |
2 |
Correct |
8 ms |
888 KB |
Output is correct |
3 |
Correct |
17 ms |
5752 KB |
Output is correct |
4 |
Correct |
15 ms |
3832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
504 KB |
Output is correct |
2 |
Correct |
12 ms |
376 KB |
Output is correct |
3 |
Correct |
61 ms |
7040 KB |
Output is correct |
4 |
Correct |
66 ms |
6776 KB |
Output is correct |
5 |
Correct |
24 ms |
2040 KB |
Output is correct |
6 |
Correct |
13 ms |
3448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
504 KB |
Output is correct |
2 |
Correct |
9 ms |
504 KB |
Output is correct |
3 |
Correct |
9 ms |
504 KB |
Output is correct |
4 |
Correct |
8 ms |
376 KB |
Output is correct |
5 |
Correct |
11 ms |
3192 KB |
Output is correct |
6 |
Correct |
8 ms |
888 KB |
Output is correct |
7 |
Correct |
17 ms |
5752 KB |
Output is correct |
8 |
Correct |
15 ms |
3832 KB |
Output is correct |
9 |
Correct |
14 ms |
504 KB |
Output is correct |
10 |
Correct |
12 ms |
376 KB |
Output is correct |
11 |
Correct |
61 ms |
7040 KB |
Output is correct |
12 |
Correct |
66 ms |
6776 KB |
Output is correct |
13 |
Correct |
24 ms |
2040 KB |
Output is correct |
14 |
Correct |
13 ms |
3448 KB |
Output is correct |
15 |
Correct |
22 ms |
1656 KB |
Output is correct |
16 |
Correct |
44 ms |
5084 KB |
Output is correct |
17 |
Correct |
114 ms |
10772 KB |
Output is correct |
18 |
Correct |
41 ms |
4604 KB |
Output is correct |
19 |
Correct |
12 ms |
376 KB |
Output is correct |