Submission #414567

#TimeUsernameProblemLanguageResultExecution timeMemory
414567cfalasCarnival Tickets (IOI20_tickets)C++14
27 / 100
3059 ms193460 KiB
#include "tickets.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

#define MINUS 2*MOD+2
#define PLUS MOD+1

long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	vector<vi> answer(n);
	vector<multiset<ii> > rem(n);
	answer.assign(n, vector<int>(m, -1));
	FOR(i,n) FOR(j,m) rem[i].insert({x[i][j], j});

	ll ans=0;

	FOR(round,k){
		vii maxa, mina;
		FOR(i,n){
			if(rem[i].size())
				maxa.push_back({ - (*rem[i].begin()).F - (*(rem[i].rbegin())).F, i});
		}
		sort(maxa.begin(), maxa.end());

		set<ii> to_er;
		FOR(i,n){
			ii t = *rem[i].begin();
			answer[i][t.S] = MINUS+round;
			to_er.insert({i, t.S});
			ans -= t.F;
		}
		FOR(i,n/2){
			assert(rem[maxa[i].S].size());
			ii t = *(rem[maxa[i].S].rbegin());
			ii tp = *(rem[maxa[i].S].begin());

			assert(maxa[i].F==-t.F-tp.F);
			ans -= maxa[i].F;

			answer[maxa[i].S][tp.S] = -1;
			to_er.erase({maxa[i].S, tp.S});

			answer[maxa[i].S][t.S] = PLUS+round;
			to_er.insert({maxa[i].S, t.S});
		}
		FOA(v, to_er){
			rem[v.F].erase(rem[v.F].find({x[v.F][v.S], v.S}));
		}
		/*
		FOR(i,n){
			FOR(j,m){
				if(answer[i][j]>=MINUS) cout<<" - ";
				else if(answer[i][j]>=PLUS && answer[i][j]<=MINUS) cout<<" + ";
				else cout<<answer[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;*/
	}

	FOR(rnd,k){
		vector<iii> pc;
		FOR(i,n){
			int p=0;
			int lp=0;
			FOR(j,m) if(answer[i][j]>=PLUS && answer[i][j]<MINUS) p++, lp=j;
			pc.push_back({{-p,i},lp});
		}
		sort(pc.begin(), pc.end());
		set<int> used;
		FOR(i,n/2){
			used.insert(pc[i].F.S);
			answer[pc[i].F.S][pc[i].S] = rnd;
		}
		FOR(i,n) if(!used.count(i)){
			bool f = false;
			FOR(j,m) if(answer[i][j]>=MINUS){
				answer[i][j] = rnd;
				f = true;
				break;
			}
			assert(f);
		}
		/*
		FOR(i,n){
			FOR(j,m) cout<<answer[i][j]<<" ";
			cout<<endl;
		}*/
	}
	
	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...