이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll find_maximum(int k, vector<vector<int>> x) {
ll n = x.size(), m = x[0].size(),
sum = 0, need = k*n/2, id[n];
int chosen[n][m];
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
chosen[i][j] = 0;
vector<vector<int>> s(n);
priority_queue<pair<ll, ll>> change;
for(int i = 0; i < n; i++) {
id[i] = m-k;
s[i].resize(m);
sort(x[i].begin(), x[i].end());
for(int j = 0; j < m; j++)
s[i][j] = -1;
for(int j = id[i]; j < m; j++) {
sum += x[i][j];
chosen[i][j] = 1;
}
change.push({- x[i][0] - x[i][m-k], i});
}
while(need--) {
pair<ll, ll> pii = change.top();
change.pop();
sum += pii.first;
ll lig = pii.second, rempl = id[lig] - (m-k);
chosen[lig][rempl] = -1;
if(rempl != id[lig])
chosen[lig][id[lig]] = 0;
id[lig]++;
if(id[lig] < m)
change.push({- x[lig][id[lig] - (m-k)] - x[lig][id[lig]], lig});
}
vector<int> inf[n], sup[n];
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(chosen[i][j] == 1)
sup[i].push_back(j);
else if(chosen[i][j] == -1)
inf[i].push_back(j);
int mid = n/2;
for(int i = 0; i < k; i++) {
pair<int, int> iLig[n];
for(int j = 0; j < n; j++)
iLig[j] = {sup[j].size(), j};
sort(iLig, iLig + n);
for(int j = 0; j < mid; j++) {
int lig = iLig[j].second;
s[lig][inf[lig].back()] = i;
inf[lig].pop_back();
}
for(int j = mid; j < n; j++) {
int lig = iLig[j].second;
s[lig][sup[lig].back()] = i;
sup[lig].pop_back();
}
}
allocate_tickets(s);
return sum;
}
# | 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... |