제출 #397175

#제출 시각아이디문제언어결과실행 시간메모리
397175Antekb카니발 티켓 (IOI20_tickets)C++14
27 / 100
677 ms51528 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
typedef pair<int, int> pii;
typedef long long ll;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	int ile[n], ile2[n], uzy[n];
	for(int i=0; i<n; i++){
		uzy[i]=ile[i]=0;
		ile2[i]=m-1;
	}
	ll ans=0;
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row(m);
		answer.pb(row);
	}
	priority_queue<pair<int, int> > Q;
	for(int j=0; j<n; j++){	
		Q.push(mp(x[j][ile[j]]+x[j][ile2[j]], j));
	}
	for(int i=0; i<k*n/2; i++){
		pii a=Q.top();
		Q.pop();
		ans+=x[a.nd][ile2[a.nd]];
		answer[a.nd][ile2[a.nd]]=i;
		ile2[a.nd]--;
		if(++uzy[a.nd]<k)Q.push(mp(x[a.nd][ile[a.nd]]+x[a.nd][ile2[a.nd]], a.nd));
	}
	while(Q.size())Q.pop();
	for(int j=0; j<n; j++){	
		if(uzy[j]<k)Q.push(mp(-x[j][ile[j]]-x[j][ile2[j]], j));
	}
	for(int i=0; i<k*n/2; i++){
		pii a=Q.top();
		Q.pop();
		ans-=x[a.nd][ile[a.nd]];
		answer[a.nd][ile[a.nd]]=i;
		ile[a.nd]++;
		if(++uzy[a.nd]<k)Q.push(mp(-x[a.nd][ile[a.nd]]-x[a.nd][ile2[a.nd]], a.nd));
	}
	for(int i=1; i<=k; i++){
		vector<int> todo;
		int a=0, b=0;
		for(int j=0; j<n; j++){
			if(ile[j]==0)a++, answer[j][++ile2[j]]=i;
			else if(ile2[j]==m-1)b++, answer[j][--ile[j]]=i;
			else todo.pb(j);
		}
		for(int j:todo){
			if(a<n/2){
				a++;
				answer[j][++ile2[j]]=i;
			}
			else{
				b++;
				answer[j][--ile[j]]=i;
			}
		}
	}
	for(auto &i:answer){
		for(auto &j:i)j--;
	}
	allocate_tickets(answer);
	return ans;
}
#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...