제출 #834854

#제출 시각아이디문제언어결과실행 시간메모리
834854Johann카니발 티켓 (IOI20_tickets)C++14
100 / 100
951 ms110576 KiB
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

long long find_maximum(int K, std::vector<std::vector<int>> x)
{
	int N = x.size();
	int M = x[0].size();

	ll value = 0;
	vvi ans(N, vi(M, -1));
	vvi mapping(N, vi(M, -1)); // mapping of pairs
	vvi useNega(N, vi(M, 0));

	vpii gains;
	for (int i = 0; i < N; ++i)
	{
		vpii A(M);
		for (int j = 0; j < M; ++j)
			A[j] = {x[i][j], i * M + j};
		sort(all(A));
		int delta = M - K;
		for (int j = 0; j < K; ++j)
		{
			value -= A[j].first;
			useNega[i][A[j].second % M] = 1; // i use it as a negative
			mapping[i][A[j + delta].second % M] = A[j].second % M;
			gains.push_back({A[j].first + A[j + delta].first, A[j + delta].second});
		}
	}
	sort(all(gains));
	reverse(all(gains));
	gains.resize(K * N / 2);

	sort(all(gains), [&](const pii &a, const pii &b)
		 { return a.second / M < b.second / M; });

	vvi RoundUsed(N, vi(K, 0));
	for (int l = 0, i, j; l < K * N / 2; ++l)
	{
		pii tmp = gains[l];

		i = tmp.second / M, j = tmp.second % M;
		value += tmp.first;

		useNega[i][mapping[i][j]] = 0;
		ans[i][j] = l % K;
		RoundUsed[i][l % K] = 1;
	}

	for (int i = 0; i < N; ++i)
	{
		int k = 0;
		for (int j = 0; j < M; ++j)
			if (useNega[i][j])
			{
				while (RoundUsed[i][k])
					++k;
				ans[i][j] = k++;
			}
	}

	allocate_tickets(ans);

	return value;
}
#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...