이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include "tickets.h"
using namespace std;
#define f first
#define s second
long long find_maximum(int k, vector<vector<int>> x){
int n = x.size();
int m = x[0].size();
if (m == 1){
vector<int> vec;
for (int i=0;i<n;i++)
vec.push_back(x[i][0]), x[i][0] = 0;
sort(begin(vec), end(vec));
long long ans = 0;
for (int i=0;i<n;i++)
ans += abs(vec[n / 2] - vec[i]);
allocate_tickets(x);
return ans;
}
vector<pair<pair<int,int>,int>> vec;
for (int i=0;i<n;i++){
vec.push_back({{x[i][0], x[i][m-1]}, i});
for (int j=0;j<m;j++)
x[i][j] = -1;
}
sort(begin(vec), end(vec));
multiset<pair<int,int>> ms;
int h = n / 2;
long long Mx = -1, ans = 0, ind = h - 1;
for (int i=h-1;i<=n;i++){
bool fl = false;
if (i == n){
i = ind;
x[vec[i].s][0] = 0;
fl = true;
}
int b = vec[i].f.f;
ans = 0;
ms.clear();
for (int j=0;j<i;j++){
ans += b - vec[j].f.f;
if (vec[j].f.s >= b)
ms.insert({vec[j].f.s - b - b + vec[j].f.f, vec[j].s});
if (fl)
x[vec[j].s][0] = 0;
}
int rem = h;
for (int j=i+1;j<n;j++){
ans += vec[j].f.s - b;
if (fl)
x[vec[j].s][m-1] = 0;
rem--;
}
if (rem > ms.size())
continue;
while (rem--){
auto [a, b] = *rbegin(ms);
ans += a;
if (fl){
x[b][0] = -1;
x[b][m-1] = 0;
}
ms.erase(prev(end(ms)));
}
if (fl)
break;
if (ans > Mx)
Mx = ans, ind = i;
}
allocate_tickets(x);
return Mx;
}
컴파일 시 표준 에러 (stderr) 메시지
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:67:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::multiset<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if (rem > ms.size())
| ~~~~^~~~~~~~~~~
# | 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... |