Submission #823440

#TimeUsernameProblemLanguageResultExecution timeMemory
823440NothingXDCarnival Tickets (IOI20_tickets)C++17
100 / 100
687 ms80936 KiB
#include "tickets.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr<<endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 1500 + 10;
const ll inf = 1e18;
int n, m, k, x[maxn][maxn], val[maxn];
ll a[maxn][maxn];
int ptl[maxn], ptr[maxn];

bool cmp(int x, int y){
	return val[x] > val[y];
}

ll find_maximum(int _k, vector<vector<int>> X) {
	n = X.size();
	m = X[0].size();
	k = _k;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			x[i][j] = X[i][j];
		}
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < k; j++){
			a[i][0] -= x[i][j];
		}
		for (int j = 1; j <= k; j++){
			a[i][j] = a[i][j-1];
			a[i][j] += x[i][k-j];
			a[i][j] += x[i][m-j];
		}
	}
	ll res = 0;
	set<pll> st;
	for (int i = 0; i < n; i++){
		st.insert({a[i][1]-a[i][0], i});
		res += a[i][0];
	}
	for (int cnt = 1; cnt <= n*k/2; cnt++){
		auto it = st.end();
		it--;
		pii tmp = *it;
	//	debug(tmp.F, tmp.S);
		st.erase(it);
		res += tmp.F;
		val[tmp.S]++;
		if (val[tmp.S] < k) st.insert({a[tmp.S][val[tmp.S]+1]-a[tmp.S][val[tmp.S]], tmp.S});
	}
	//for (int i = 0; i < n; i++){
	//	debug(i, val[i]);
	//}
	vector<vector<int>> ans(n);
	for (int i = 0; i < n; i++){
		ptr[i] = m-1;
		ans[i].resize(m, -1);
	}
	for (int rnd = 0; rnd < k; rnd++){
		//debug(rnd);
		vector<int> idx;
		for (int i = 0; i < n; i++){
			idx.push_back(i);
		}
		sort(idx.begin(), idx.end(), cmp);
		for (int i = 0; i < n; i++){
			if (i < n/2){
				ans[idx[i]][ptr[idx[i]]] = rnd;
				val[idx[i]]--;
				ptr[idx[i]]--;
			}
			else{
				ans[idx[i]][ptl[idx[i]]] = rnd;
				ptl[idx[i]]++;
			}
		}
	}
	allocate_tickets(ans);
	return res;
}
#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...