This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include "tickets.h"
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> answer(n, vector<int>(m, -1));
vector<vector<int>> side(n, vector<int>(m, -1));
priority_queue<tuple<int, int, int>> pq;
long long sol = 0;
for (int i = 0; i < n; ++i) {
for (int j(0); j < k; ++j) {
int other = m - k + j;
sol -= x[i][j];
side[i][j] = 0;
pq.emplace(x[i][j] + x[i][other], i, j);
}
}
while ((int)pq.size() > n * k / 2) {
auto [delta, i, j] = pq.top();
int other = m - k + j;
pq.pop();
sol += delta;
side[i][j] = -1;
side[i][other] = 1;
}
vector<vector<int>> posLeft(n), posRight(n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
if (side[i][j] == 1)
posRight[i].push_back(j);
else if (side[i][j] == 0)
posLeft[i].push_back(j);
}
for (int round = 0; round < k; ++round) {
vector<bool> picked(n);
int gaucheNec = n / 2, droiteNec = n / 2;
for (int col = 0; col < n; ++col) {
if (posLeft[col].empty()) {
picked[col] = true;
answer[col][posRight[col].back()] = round;
posRight[col].pop_back();
droiteNec--;
} else if (posRight[col].empty()) {
picked[col] = true;
answer[col][posLeft[col].back()] = round;
posLeft[col].pop_back();
gaucheNec--;
}
}
for (int col = 0; col < n; ++col) {
if (picked[col])
continue;
assert(!posLeft[col].empty() and !posRight[col].empty());
if (gaucheNec > 0) {
answer[col][posLeft[col].back()] = round;
posLeft[col].pop_back();
gaucheNec--;
} else {
assert(droiteNec > 0);
answer[col][posRight[col].back()] = round;
posRight[col].pop_back();
droiteNec--;
}
}
}
allocate_tickets(answer);
return sol;
}
# | 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... |