Submission #489717

# Submission time Handle Problem Language Result Execution time Memory
489717 2021-11-24T03:35:00 Z 8e7 Carnival Tickets (IOI20_tickets) C++17
0 / 100
1 ms 332 KB
#include "tickets.h"
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <random>
#include <chrono>
using namespace std;
void debug(){cout << endl;}
template<class T, class ...U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary (T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#define ll long long
#define maxn 85
#define pii pair<int, int>
#define ff first
#define ss second
const ll inf = 1LL<<60;
ll dp[maxn][maxn*maxn], cost[maxn][maxn];
int prv[maxn][maxn*maxn], pref[maxn], suf[maxn];
long long find_maximum(int k, vector<vector<int> > x) {
	int n = x.size();
	int m = x[0].size();
	ll tot = 0;
	for (int i = 0;i < n;i++) {
		for (int j = m - k;j < m;j++) {
			tot += x[i][j];
			cost[i][j - m + k + 1] = -x[i][j - m + k] - x[i][j];
		}	
		for (int j = 1;j <= k;j++) cost[i][j] += cost[i][j-1];
		//pary(cost[i], cost[i] + k + 1);
	}
	vector<vector<int> > ans(n, vector<int>(m, -1));
	for (int j = 0;j <= n;j++) {
		for (int i = 1;i <= n * k;i++) dp[j][i] = -inf;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			for (int c = 0;c <= n * k / 2 - j;c++) {
				ll val = dp[i][c] + cost[i][j];
				if (val > dp[i+1][j+c]) {
					dp[i+1][j+c] = val;
					prv[i+1][j+c] = j;
				}
			}
		}
	}
	int cur = n * k / 2;
	for (int i = n;i > 0;i--) {
		pref[i-1] = prv[i][cur];
		suf[i-1] = n - (k - pref[i-1]);	
		cur -= prv[i][cur];
	}
	for (int ti = 0;ti < k;ti++) {
		int rem = n / 2;
		for (int i = 0;i < n;i++) {
			if (pref[i] && rem) {
				rem--;
				pref[i]--;
				ans[i][pref[i]] = ti;
			} else {
				suf[i]++;
				ans[i][suf[i]] = ti;
			}
		}
	}	
	allocate_tickets(ans);
	//debug(tot, dp[n][n*k/2]);
	return tot + dp[n][n*k/2];
}
/*
2 3 2
0 2 5
1 1 3
*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB There is no ticket of color 1 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB There is no ticket of color 1 on day 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB There is no ticket of color 0 on day 2
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB There is no ticket of color 1 on day 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB There is no ticket of color 1 on day 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB There is no ticket of color 1 on day 3
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB There is no ticket of color 1 on day 0
2 Halted 0 ms 0 KB -