제출 #1228916

#제출 시각아이디문제언어결과실행 시간메모리
1228916The_Samurai카니발 티켓 (IOI20_tickets)C++17
100 / 100
858 ms94004 KiB
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;

long long find_maximum(int k, std::vector<std::vector<int>> a) {
	int n = a.size();
	int m = a[0].size();
	vector<int> pos(n);
	vector vec(n, vector(m, -1));
	ll ans = 0;
	for (int i = 0; i < n; i++) for (int j = m - k; j < m; j++) ans += a[i][j];
	priority_queue<pair<ll, int>> pq;
	for (int i = 0; i < n; i++) pq.emplace(-a[i][0] - a[i][m - k], i);
	for (int shit = 0; shit < n * k / 2; shit++) {
		auto [d, i] = pq.top(); pq.pop();
		ans += d;
		pos[i]++;
		if (pos[i] < k) pq.emplace(-a[i][pos[i]] - a[i][m - (k - pos[i])], i);
	}
	vector<set<pair<int, int>>> right(n);
	vector<vector<int>> left(n);
	vector<int> taken(n);
	vector<pair<int, int>> have(n);
	for (int i = 0; i < n; i++) {
		vector<int> v;
		for (int j = 0; j < pos[i]; j++) v.emplace_back(a[i][j]);
		for (int j = m - (k - pos[i]); j < m; j++) right[i].emplace(a[i][j], j);
		left[i] = v;
		have[i] = make_pair(pos[i], i);
	}
	for (int shit = 0; shit < k; shit++) {
		sort(have.rbegin(), have.rend());
		vector<bool> used(n);
		vector<int> v;
		int cnt = 0, mx = 0;
		for (int i = 0; i < n / 2; i++) {
			used[have[i].second] = true;
			have[i].first--;
			mx = max(mx, a[have[i].second][taken[have[i].second]]);
			vec[have[i].second][taken[have[i].second]++] = shit;
		}
		for (int i = 0; i < n; i++) {
			if (used[i]) continue;
			auto it = right[i].lower_bound(make_pair(mx, 0));
			vec[i][it->second] = shit;
			right[i].erase(it);
		}
	}
	allocate_tickets(vec);
	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...