This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 510;
int n, k, c;
int cc[N][10], rnk[10][N], id;
bool cmp(int a, int b) {
return cc[a][id] > cc[b][id];
}
struct node{
bitset <510> ban;
vector <int> used;
ll sum = 0, id;
void calculate(int _id, bitset<510> _ban) {
id = _id;
ban = _ban;
for (int j = 1; j <= k; j++) {
for (int i = 1; i <= n; i++) {
if (ban[rnk[j][i]] == 0) {
used.pb(rnk[j][i]);
ban[rnk[j][i]] = 1;
break;
}
}
}
vector <int> score(k + 1, 0);
for (auto x : used) {
for (int i = 1; i <= k; i++)
score[i] = max(score[i], cc[x][i]);
}
for (int i = 1; i <= k; i++)
sum += score[i];
for (auto x : used)
ban[x] = 0;
}
};
bool operator<(const node& A, const node& B) {
return A.sum < B.sum;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> c;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> cc[i][j];
}
}
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++)
rnk[i][j] = j;
id = i;
sort(rnk[i] + 1, rnk[i] + 1 + n, cmp);
}
bitset <510> bt;
node ss;
ss.calculate(0, bt);
priority_queue <node> pq;
pq.push(ss);
ll ans = 0;
for (int i = 1; i <= c; i++) {
auto t = pq.top();
pq.pop();
ans = t.sum;
int id = t.id;
auto ban = t.ban;
while (id < k) {
ban[t.used[id]] = 1;
node ss;
ss.calculate(id, ban);
ban[t.used[id]] = 0;
if (sz(ss.used) == k) {
pq.push(ss);
}
id++;
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |