이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
#define F first
#define S second
typedef long long ll;
ll find_maximum(int k, std::vector<std::vector<int>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<int>> answer(n,vector<int>(m,-1));
std::vector<std::vector<int>> answer2(n,vector<int>(m,-1));
if(m == 1){
ll val = 0;
vector<int> temp;
for (int i = 0; i < n; i++) {
answer[i][0] = 0;
temp.push_back(x[i][0]);
}
sort(temp.begin(),temp.end());
for (int i = 0; i < n/2; i++)val -= temp[i];
for (int i = n/2; i < n; i++)val += temp[i];
allocate_tickets(answer);
return val;
}
if(k == 1){
priority_queue<pair<int,int>> plus,minus;
int val = 0;
for (int i = 0; i < n; i++)plus.push({x[i][m-1],i});
for (int i = 0; i < n; i++)minus.push({-x[i][0],i});
vector<int> used(n,0);
ll ans = 0;
for(int i = 0;i<n/2;i++){
ans += plus.top().F;
used[plus.top().S] = 1;
answer2[plus.top().S][m-1] = 0;
plus.pop();
}
for(int i = 0;i<n/2;i++){
auto a = minus.top();minus.pop();
if(used[a.S]){
i--;
continue;
}
ans += a.F;
answer2[a.S][0] = 0;
}
val = ans;
plus = priority_queue<pair<int,int>>();
minus = priority_queue<pair<int,int>>();
for (int i = 0; i < n; i++)plus.push({x[i][m-1],i});
for (int i = 0; i < n; i++)minus.push({-x[i][0],i});
used = vector<int> (n,0);
ans = 0;
for(int i = 0;i<n/2;i++){
ans += plus.top().F;
used[plus.top().S] = 1;
answer[plus.top().S][m-1] = 0;
plus.pop();
}
for(int i = 0;i<n/2;i++){
auto a = minus.top();minus.pop();
if(used[a.S]){
i--;
continue;
}
ans += a.F;
answer[a.S][0] = 0;
}
if(ans > val){
allocate_tickets(answer);
return ans;
}else{
allocate_tickets(answer2);
return val;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'll find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:14:58: warning: control reaches end of non-void function [-Wreturn-type]
14 | std::vector<std::vector<int>> answer(n,vector<int>(m,-1));
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |