이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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});
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
olympiads.cpp: In function 'std::vector<int> getbest(std::vector<int>)':
olympiads.cpp:11:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (int j=i+1; j<indices.size(); j++) {
| ~^~~~~~~~~~~~~~~
olympiads.cpp: In function 'int evaluate_combination(std::vector<int>)':
olympiads.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i=0; i<indices.size(); i++) {
| ~^~~~~~~~~~~~~~~
olympiads.cpp: In function 'int main()':
olympiads.cpp:73:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
73 | if (indices.size()==k) {
| ~~~~~~~~~~~~~~^~~
# | 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... |