이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sz(a) ((int)(a).size())
typedef vector<int> vint;
typedef vector<vint> vvint;
#ifndef wambule
#include "tickets.h"
#else
void allocate_tickets(vvint a) {
int n = a.size();
int m = a.begin()->size();
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
cout << a[i][j] << " ";
}
cout << "\n";
}
}
#endif
long long find_maximum(int k, vvint x) {
int n = x.size();
int m = x.begin()->size();
vint v(n, 0);
priority_queue<pair<int, int>> pq;
long long dr = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < k; ++j) {
dr -= x[i][j];
}
pq.push({x[i][k - 1] + x[i][m - 1], i});
}
for(int i = 0; i < n * k / 2; ++i) {
int y = pq.top().second;
dr += pq.top().first;
pq.pop();
++v[y];
if(v[y] < k) {
pq.push({x[y][k - 1 - v[y]] + x[y][m - 1 - v[y]], y});
}
}
vector<pair<pair<int, int>, int>> u;
for(int i = 0; i < n; ++i) {
u.push_back({{k - 1 - v[i], m - v[i]}, i});
}
vvint fp(n, vint(m, -1));
for(int i = 0; i < k; ++i) {
sort(u.begin(), u.end());
for(int j = 0; j < n; ++j) {
int y = 0;
if(j < n / 2) {
y = u[j].first.second++;
} else {
y = u[j].first.first--;
}
fp[u[j].second][y] = i;
}
}
allocate_tickets(fp);
return dr;
}
#ifdef wambule
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << find_maximum(2, {{0, 2, 5}, {1, 1, 3}}) << endl << endl;
cout << find_maximum(1, {{5, 9}, {1, 4}, {3, 6}, {2, 7}}) << endl << endl;
return 0;
}
#endif
# | 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... |