이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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));
vector<tuple<int, int, int>> swaps;
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;
swaps.emplace_back(x[i][j] + x[i][other], i, j);
}
}
sort(swaps.rbegin(), swaps.rend());
for (int a(0); a < n * k / 2; ++a) {
auto [delta, i, j] = swaps[a];
int other = m - k + j;
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... |