이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
using namespace std;
typedef pair<int, int> pii;
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> ans = vector<vector<int>>(n, vector<int>(m, -1));
deque<pii> unused[n], mins[n], maxs[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
unused[i].push_back({x[i][j], j});
sort(unused[i].begin(), unused[i].end());
}
priority_queue<pii> best;
long long win = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
// cerr << "Unused: " << unused[i].begin()->first << endl;
win -= unused[i].begin()->first;
mins[i].push_back(*unused[i].begin());
unused[i].pop_front();
}
best.push({mins[i].rbegin()->first + (unused[i].size() ? unused[i].rbegin()->first : mins[i].rbegin()->first), i});
// cerr << "Inserted: " << mins[i].rbegin()->first << endl;
}
for (int ix = 0; ix < k * n / 2; ix++) {
pii b = best.top();
best.pop();
win += b.first;
int c = b.second;
// cerr << b.first << endl;
if (unused[c].size()) {
maxs[c].push_front(*unused[c].rbegin());
unused[c].pop_back();
unused[c].push_front(*mins[c].rbegin());
} else {
maxs[c].push_front(*mins[c].rbegin());
}
mins[c].pop_back();
if (mins[c].size()) {
best.push({mins[c].rbegin()->first + (unused[c].size() ? unused[c].rbegin()->first : mins[c].rbegin()->first), c});
}
}
for (int r = 0; r < k; r++) {
vector<pii> c;
for (int j = 0; j < n; j++) {
c.push_back({maxs[j].size(), j});
// cout << c.back().first << ' ';
}
// cout << endl;
sort(c.begin(), c.end());
for (int i = 0; i < n / 2; i++) {
int col = c[i].second;
int ix = mins[col].begin()->second;
ans[col][ix] = r;
mins[col].pop_front();
}
for (int i = n / 2; i < n; i++) {
int col = c[i].second;
int ix = maxs[col].begin()->second;
ans[col][ix] = r;
maxs[col].pop_front();
}
}
allocate_tickets(ans);
return win;
}
# | 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... |