이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define i2 array<int,2>
using namespace std;
typedef long long ll;
const int N = 1600;
const ll OO = 1e18;
priority_queue<i2> pq;
int ptr[N], cand[N], siz[N];
bool was[N][N];
long long find_maximum(int k, vector<vector<int>> x) {
int n = x.size();
int m = x[0].size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row(m);
fill(all(row), -1);
answer.push_back(row);
}
ll ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++)
ans += x[i][m - k + j];
ptr[i] = 0;
cand[i] = 0;
pq.push({-x[i][m - k] - x[i][0], i});
}
// add again to pq only if ptr < m
for (int itr = (n / 2) * k; itr > 0; itr--){
i2 now = pq.top(); pq.pop();
ans += now[0];
int id = now[1];
while (cand[id] < k && siz[cand[id]] == n / 2){
cand[id]++;
}
assert(cand[id] < k);
was[id][cand[id]] = 1;
siz[cand[id]]++;
answer[id][ptr[id]] = cand[id]++;
ptr[id]++;
if (ptr[id] < k){
pq.push({-x[id][m - k + ptr[id]] - x[id][ptr[id]], id});
}
}
// add last tickets
for (int i = 0; i < n; i++){
int now = 0;
for (int j = ptr[i]; j < k; j++){
while (now < k && was[i][now]) now++;
assert(now < k);
was[i][now] = 1;
answer[i][m - k + j] = now++;
}
}
allocate_tickets(answer);
return ans;
}
# | 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... |