이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define dbg(x) cerr << #x << ": " << x << endl;
ll find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> res(n, vector<int>(m, -1));
vector<vector<int>> sign(n, vector<int>(m));
vector<vector<int>> minus_sign(n);
vector<vector<int>> plus_sign(n);
priority_queue<pair<int, int>> pq;
vector<int> first(n, k - 1);
vector<int> last(n, m - 1);
ll ans = 0;
for (int i = 0; i < n; ++i) {
pq.emplace(x[i][first[i]] + x[i][last[i]], i);
for (int j = 0; j < k; ++j) {
sign[i][j] = -1;
ans -= x[i][j];
}
}
for (int t = 0; t < n * k / 2; ++t) {
auto [value, i] = pq.top();
pq.pop();
ans += value;
sign[i][first[i]] = 0;
sign[i][last[i]] = 1;
if (first[i] > 0) {
--first[i];
--last[i];
pq.emplace(x[i][first[i]] + x[i][last[i]], i);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (sign[i][j] == 1) plus_sign[i].push_back(j);
else if (sign[i][j] == -1) minus_sign[i].push_back(j);
}
}
for (int t = 0; t < k; ++t) {
vector<int> p(n);
iota(p.begin(), p.end(), 0);
sort(p.begin(), p.end(), [&](int lhs, int rhs) {
return plus_sign[lhs].size() < plus_sign[rhs].size();
});
for (int i = 0; i < n / 2; ++i) {
res[p[i]][minus_sign[p[i]].back()] = t;
minus_sign[p[i]].pop_back();
}
for (int i = n / 2; i < n; ++i) {
res[p[i]][plus_sign[p[i]].back()] = t;
plus_sign[p[i]].pop_back();
}
}
allocate_tickets(res);
return ans;
}
// int main() {
// int n, m, k;
// cin >> n >> m >> k;
// vector<vector<int>> a(n, vector<int>(m));
// for (int i = 0; i < n; ++i) {
// for (int j = 0; j < m; ++j) {
// cin >> a[i][j];
// }
// }
// cout << find_maximum(k, a) << '\n';
// }
/*
4 3 2
0 3 4
0 0 2
1 2 4
0 4 4
right:
15
*/
# | 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... |