제출 #1017836

#제출 시각아이디문제언어결과실행 시간메모리
1017836nickolasarapidisCarnival Tickets (IOI20_tickets)C++17
11 / 100
2 ms860 KiB
/*
	IOI 2020
	Day 1 - problem 3 (tickets)
	Author: Nickolas Arapidis
*/
#include "tickets.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define F first
#define S second
#define MP make_pair

ll calculate_score(vector<int> A){
	int N = A.size();

	ll sum = 0;

	int mid = A[N/2];

	for(int i = 0; i < N; i++){
		sum += abs(A[i] - mid);
	}

	return sum;
}

ll find_maximum(int k, vector<vector<int>> X){
	ll ans = 0;

	int N = X.size(); // Ammount of colors
	int M = X[0].size(); // Ammount of tickets for each color

	vector<int> s(M, -1);
	vector<vector<int>> S(N, s);

	vector<int> large;
	vector<int> small;
	vector<int> A;
	vector<pair<int, int> > B(N, {0, 0});

	for(int i = 0; i < k; i++){
		large.clear();
		small.clear();
		A.clear();

		map<int, pair<int, int> > l;
		map<int, pair<int, int> > s;

		for(int j = 0; j < N; j++){
			large.push_back(X[j][(M - 1) - B[j].S]);
			small.push_back(X[j][0 + B[j].F]);
			l[large.back()] = MP(j, (M - 1) - B[j].S);
			s[small.back()] = MP(j, 0 + B[j].F);
		}

		sort(large.begin(), large.end());
		sort(small.begin(), small.end());

		for(int j = 0; j < N/2; j++){
			A.push_back(small[j]);
			S[s[A.back()].first][s[A.back()].second] = i;
			B[s[A.back()].first].first++;
		}

		for(int j = N/2; j < N; j++){
			A.push_back(large[j]);
			S[l[A.back()].first][l[A.back()].second] = i;
			B[s[A.back()].first].second++;
		}

		ans += calculate_score(A);
	}

	allocate_tickets(S);

	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...