Submission #397210

#TimeUsernameProblemLanguageResultExecution timeMemory
397210AntekbCarnival Tickets (IOI20_tickets)C++14
39 / 100
3093 ms128968 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
typedef pair<int, int> pii;
typedef long long ll;
const ll INF=100000000000000;
long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int n = x.size();
	int m = x[0].size();
	int ile[n], ile2[n];
	ll sum[n][k+1], dp[n+1][k*n/2+1], skad[n+1][k*n/2+1];
	ll ans=0;
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row(m);
		answer.pb(row);
	}
	for(int i=0; i<n; i++){
		sum[i][k]=0;
		for(int j=0; j<k; j++){
			sum[i][k]+=x[i][m-1-j];
		}
		for(int j=k-1; j>=0; j--){
			sum[i][j]=sum[i][j+1]-x[i][m-1-j]-x[i][k-1-j];
		}
	}
	dp[0][0]=0;
	for(int j=1; j<=n*k/2; j++)dp[0][j]=-INF;
	for(int i=0; i<n; i++){
		for(int j=0; j<=n*k/2; j++){
			dp[i+1][j]=-INF;
			//cout<<i<<" "<<j<<" "<<dp[i+1][j]<<"\n";
			for(int l=0; l<=k && l<=j; l++){
				//cout<<i<<" "<<
				if(dp[i+1][j]<dp[i][j-l]+sum[i][l]){
					dp[i+1][j]=dp[i][j-l]+sum[i][l];
					skad[i+1][j]=l;
				}
			}
			//cout<<i<<" "<<j<<" "<<dp[i+1][j]<<"\n";
		}
	}
	int t=n, u=n*k/2;
	while(t){
		ile2[t-1]=m-1-skad[t][u];
		//cout<<skad[t][u]<<" "<<"\n";
		u-=skad[t][u];
		t--;
	}
	for(int i=0; i<n; i++){
		ile[i]=k-(m-1-ile2[i]);
		//cout<<ile[i]<<" "<<ile2[i]<<"\n";
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<ile[i]; j++){
			ans-=x[i][j];
			//cout<<x[i][j]<<"a";
		}
		for(int j=ile2[i]+1; j<m; j++){
			ans+=x[i][j];
			//cout<<x[i][j]<<"b";
		}
	}
	for(int i=1; i<=k; i++){
		vector<int> todo;
		int a=0, b=0;
		for(int j=0; j<n; j++){
			if(ile[j]==0)a++, answer[j][++ile2[j]]=i;
			else if(ile2[j]==m-1)b++, answer[j][--ile[j]]=i;
			else todo.pb(j);
		}
		for(int j:todo){
			if(a<n/2){
				a++;
				answer[j][++ile2[j]]=i;
			}
			else{
				b++;
				answer[j][--ile[j]]=i;
			}
		}
	}
	for(auto &i:answer){
		for(auto &j:i)j--;
	}
	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...