# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302896 | urd05 | Carnival Tickets (IOI20_tickets) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long,int> P;
static int n;
static int m;
static int k;
static std::vector<std::vector<int>> d;
static std::vector<std::vector<int>> x;
static int called = 0;
static void check(bool cond, std::string message) {
if (!cond) {
printf("%s\n", message.c_str());
exit(0);
}
}
void allocate_tickets( std::vector<std::vector<int>> _d) {
check(!called, "allocate_tickets called more than once");
d = _d;
check((int)d.size() == n, "allocate_tickets called with parameter of wrong size");
for (int i = 0; i < n; i++) {
check((int)d[i].size() == m, "allocate_tickets called with parameter of wrong size");
}
called = 1;
}
int zero[1500];
int one[1500];
int save[1500];
const int INF=1e9;
int getidx[1500][1500];
long long find_maximum(int k, vector<vector<int>> v) {
int n = v.size();
int m = v[0].size();
vector<vector<int>> answer(n,vector<int>(m));
priority_queue<P> pq;
long long ret=0;
for(int i=0;i<n;i++) {
zero[i]=min(2*k,m);
for(int j=0;j<m;j++) {
answer[i][j]=-1;
if (j<k||j>=m-k) {
pq.push(P(v[i][j],i));
}
}
}
for(int i=0;i<min((n*m)/2,n*k);i++) {
zero[pq.top().second]--;
pq.pop();
}
long long cut=pq.top().first;
for(int i=0;i<n;i++) {
one[i]=min(2*k,m)-zero[i];
save[i]=zero[i];
int cnt=0;
for(int j=0;j<m;j++) {
if (j<k||j>=m-k) {
getidx[i][cnt++]=j;
}
}
}
for(int pos=0;pos<k;pos++) {
priority_queue<P> pq;
int pick=n/2;
vector<int> ind;
for(int i=0;i<n;i++) {
if (zero[i]==0) {
ind.push_back(i);
ret+=v[i][getidx[i][save[i]+one[i]-1]]-cut;
pick--;
continue;
}
ret+=cut-v[i][save[i]-zero[i]];
if (one[i]==0) {
continue;
}
long long big=v[i][getidx[i][save[i]+one[i]-1]]-cut;
pq.push(P(big-(cut-v[i][save[i]-zero[i]]),i));
}
for(int i=0;i<pick;i++) {
ret+=pq.top().first;
ind.push_back(pq.top().second);
pq.pop();
}
sort(ind.begin(),ind.end());
for(int i=0;i<n;i++) {
if (binary_search(ind.begin(),ind.end(),i)) {
answer[i][getidx[i][save[i]+one[i]-1]]=pos;
one[i]--;
}
else {
answer[i][getidx[i][save[i]-zero[i]]]=pos;
zero[i]--;
}
}
}
allocate_tickets(answer);
return ret;
}