Submission #302896

#TimeUsernameProblemLanguageResultExecution timeMemory
302896urd05카니발 티켓 (IOI20_tickets)C++14
Compilation error
0 ms0 KiB
#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;
}

Compilation message (stderr)

tickets.cpp:10:12: warning: 'k' defined but not used [-Wunused-variable]
   10 | static int k;
      |            ^
/tmp/ccilECD5.o: In function `allocate_tickets(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)':
grader.cpp:(.text+0x1f0): multiple definition of `allocate_tickets(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
/tmp/ccbrr7vf.o:tickets.cpp:(.text+0x20): first defined here
collect2: error: ld returned 1 exit status