# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1005657 | anango | Olympiads (BOI19_olympiads) | C++17 | 1 ms | 348 KiB |
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;
vector<vector<int>> cons;
int n,k,c;
vector<int> getbest(vector<int> indices) {
//get the best team using radix sort greedy method (the first k are the best team, rest are reserves)
for (int i=0; i<k; i++) {
for (int j=i+1; j<indices.size(); j++) {
if (cons[indices[j]][i]>cons[indices[i]][i]) {
swap(indices[i], indices[j]);
}
}
}
return indices;
}
int evaluate_combination(vector<int> indices) {
vector<int> maxes(k,0);
for (int i=0; i<indices.size(); i++) {
for (int j=0; j<k; j++) {
maxes[j]=max(maxes[j],cons[indices[i]][j]);
}
}
return accumulate(maxes.begin(), maxes.end(), (int)0);
}
signed main() {
freopen("input.txt","r", stdin);
freopen("output.txt","w",stdout);
cin >> n >> k >> c;
vector<int> start;
vector<int> totalmaxes(k,0);
for (int i=0; i<n; i++) {
start.push_back(i);
vector<int> c1;
for (int j=0; j<k; j++) {
int x;
cin >> x;
c1.push_back(x);
totalmaxes[j]=max(totalmaxes[j],x);
}
cons.push_back(c1);
}
int total = accumulate(totalmaxes.begin(), totalmaxes.end(), (int)0);
start = getbest(start);
priority_queue<vector<vector<int>>> current;
current.push({{total},{0},start});
int ct=0;
while (ct<c) {
ct++;
assert(current.size()>0);
vector<vector<int>> latest = current.top();
current.pop();
int value = latest[0][0];
vector<int> indices = latest[2];
/*cout << ct <<" " << value << " " << latest[1][0] << endl;
cout << "INDICES ";
for (auto j:indices) {
cout << j <<" ";
}
cout << endl;*/
if (ct==c) {
cout << value << endl;
return 0;
}
if (indices.size()==k) {
//leaf node
continue;
}
for (int nex=latest[1][0]; nex<k; nex++) {
//the next optimal element being removed
vector<int> new_indices(indices.begin(), indices.end());
//remove this position from the team
new_indices.erase(find(new_indices.begin(),new_indices.end(),new_indices[nex]));
new_indices = getbest(new_indices);
current.push({{evaluate_combination(new_indices)},{nex},new_indices});
}
}
}
Compilation message (stderr)
# | 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... |