이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
bool cmp(pair<pair<pair<int, int>, pair<int, int>>, int> a, pair<pair<pair<int, int>, pair<int, int>>, int> b)
{
if(a.first.first.first+b.first.second.first != a.first.second.first+b.first.first.first)
return a.first.first.first+b.first.second.first > a.first.second.first+b.first.first.first;
return a.first.first.first < b.first.first.first;
}
long long find_maximum(signed k, std::vector<std::vector<signed>> x) {
int n = x.size();
int m = x[0].size();
std::vector<std::vector<signed>> ans(n, vector<signed>(m, -1));
long long ansv = 0;
vector<multiset<pair<int, int>>> sx(n);
for (int i = 0; i < n; i++) {
for(int j = 0; j < m; j++)
sx[i].insert({x[i][j], j});
}
for(int as = 0; as < k; as++)
{
vector<pair<pair<pair<int, int>, pair<int, int>>, int>> poss;
for(int i = 0; i < n; i++)
{
poss.push_back({{*sx[i].begin(), *sx[i].rbegin()}, i});
}
sort(poss.begin(), poss.end(), cmp);
int mv = poss[n/2-1].first.first.first;
for(int i = 0; i < n/2; i++)
{
//cout << poss[i].first.first.first << ' ' << poss[i].first.first.second << '\n';
ansv += mv-poss[i].first.first.first;
ans[poss[i].second][poss[i].first.first.second] = as;
if(sx[poss[i].second].find({poss[i].first.first.first, poss[i].first.first.second}) != sx[poss[i].second].end())
sx[poss[i].second].erase(sx[poss[i].second].find({poss[i].first.first.first, poss[i].first.first.second}));
}
for(int i = n/2; i < n; i++)
{
//cout << poss[i].first.second.first << ' ' << poss[i].first.second.second << '\n';
ansv += poss[i].first.second.first-mv;
ans[poss[i].second][poss[i].first.second.second] = as;
if(sx[poss[i].second].find({poss[i].first.second.first, poss[i].first.second.second}) != sx[poss[i].second].end())
sx[poss[i].second].erase(sx[poss[i].second].find({poss[i].first.second.first, poss[i].first.second.second}));
}
}
allocate_tickets(ans);
return ansv;
}
# | 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... |