#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
int n, k, c;
vector<vector<int>> scores;
ll pownum(int a, int b) {
ll bruh = 1;
for (int i=0;i<b;i++) bruh *= a;
return bruh;
}
ll convert(vector<int> bruh) {
bruh.pop_back();
sort(bruh.begin(), bruh.end());
ll sus = 0;
for (int i=0;i<k;i++) sus += bruh[i] * pownum(100, i);
return sus;
}
int totalscore(vector<int> bruh) {
vector<int> valvec(k, 0);
for (int i=0;i<k;i++) for (int j=0;j<k;j++) valvec[i] = max(valvec[i], scores[bruh[j]][i]);
int valnum = 0;
for (int i=0;i<k;i++) valnum += valvec[i];
return valnum;
}
class compare {
public: bool operator()(vector<int> a, vector<int> b) {
return a[k] < b[k];
}
};
int main() {
cin >> n >> k >> c;
scores = vector<vector<int>>(n, vector<int> (k));
for (int i=0;i<n;i++) for (int j=0;j<k;j++) cin >> scores[i][j];
vector<int> maxvec(k, 0);
for (int i=0;i<n;i++) for (int j=0;j<k;j++) maxvec[j] = max(maxvec[j], scores[i][j]);
vector<int> notchosen, chosen;
vector<bool> ismax(k, false);
for (int i=0;i<n;i++) {
int flag = -1;
for (int j=0;j<k;j++) if (!ismax[j] && (maxvec[j] == scores[i][j])) {flag = j; break;}
if (flag == -1) {
notchosen.pb(i);
} else {
for (int j=0;j<k;j++) if (maxvec[j] == scores[i][j]) ismax[j] = true;
chosen.pb(i);
}
}
while (chosen.size() != k) {
chosen.pb(notchosen[notchosen.size() - 1]);
notchosen.pop_back();
}
chosen.pb(0);
chosen[k] = totalscore(chosen);
priority_queue<vector<int>, vector<vector<int>>, compare> pq; pq.push(chosen);
unordered_set<ll> visited;
vector<bool> curvals(n, false);
vector<int> bruh, dumbruh;
while (true) {
if (visited.find(convert(pq.top())) != visited.end()) {
pq.pop();
continue;
}
bruh = pq.top(); pq.pop();
//for (int i: bruh) cout << i << ' '; cout << convert(bruh) << endl;
for (int i=0;i<k;i++) curvals[bruh[i]] = true;
dumbruh = bruh;
for (int i=0;i<k;i++) {
for (int j=0;j<n;j++) {
dumbruh[i] = j;
if (!curvals[j] && visited.find(convert(dumbruh)) == visited.end()) {
dumbruh[k] = totalscore(dumbruh);
pq.push(dumbruh);
}
dumbruh[i] = bruh[i];
}
}
visited.insert(convert(bruh));
if (visited.size() == c) {
cout << totalscore(bruh);
break;
}
for (int i: bruh) curvals[i] = false;
}
}
| # | 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... |