Submission #1230821

#TimeUsernameProblemLanguageResultExecution timeMemory
1230821PlayVoltzCarnival Tickets (IOI20_tickets)C++20
27 / 100
346 ms78156 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

long long find_maximum(int k, vector<vector<int> > x){
	int n=x.size(), m=x[0].size();
	long long res=0;
	vector<int> l(n, k-1), r(n, m-1), cc(n, 0), plow(n, 0), phigh(n, 0);
	vector<vector<int> > ans(n, vector<int>(m, -1)), t(n, vector<int>(m, 0)), low(n), high(n);
	vector<vector<pii> > vect(n, vector<pii>(m));
	priority_queue<pii> pq;
	for (int i=0; i<n; ++i){
		for (int j=0; j<m; ++j)vect[i][j]=mp(x[i][j], j);
		sort(vect[i].begin(), vect[i].end());
		cc[i]=-k;
		for (int j=0; j<k; ++j)res-=vect[i][j].fi, t[i][vect[i][j].se]=-1;
		pq.push(mp(vect[i][l[i]].fi+vect[i][r[i]].fi, i));
	}
	for (int i=0; i<n*k/2; ++i){
		pii c=pq.top();
		pq.pop();
		res+=c.fi;
		cc[c.se]+=2;
		t[c.se][vect[c.se][l[c.se]].se]=0;
		t[c.se][vect[c.se][r[c.se]].se]=1;
		--l[c.se];
		--r[c.se];
		if (l[c.se]>=0)pq.push(mp(vect[c.se][l[c.se]].fi+vect[c.se][r[c.se]].fi, c.se));
	}
	for (int i=0; i<n; ++i)for (int j=0; j<m; ++j){
		if (t[i][j]<0)low[i].pb(j);
		if (t[i][j]>0)high[i].pb(j);
	}
	for (int i=0; i<k; ++i){
		int bal=0;
		for (int j=0; j<n; ++j){
			if (cc[j]<0){
				ans[j][low[j][plow[j]]]=i;
				++plow[j];
				++cc[j];
				--bal;
			}
			else if (cc[j]>0){
				ans[j][high[j][phigh[j]]]=i;
				++phigh[j];
				--cc[j];
				++bal;
			}
			else{
				if (bal<=0){
					ans[j][high[j][phigh[j]]]=i;
					++phigh[j];
					--cc[j];
					++bal;
				}
				else{
					ans[j][low[j][plow[j]]]=i;
					++plow[j];
					++cc[j];
					--bal;
				}
			}
		}
	}
	allocate_tickets(ans);
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...