Submission #871448

#TimeUsernameProblemLanguageResultExecution timeMemory
871448Cyber_WolfThe short shank; Redemption (BOI21_prison)C++17
15 / 100
177 ms4468 KiB
#include <bits/stdc++.h>

using namespace std;

#define lg long long 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const lg N = 505;

lg n, d, tim;
lg dp[N][N];
lg t[N], lst[N];
vector<lg> o[N];

lg C(lg i, lg j)
{
	lg ans = o[j].size()-(lower_bound(o[j].begin(), o[j].end(), i)-o[j].begin());
	return ans;
}

int main()
{
	fastio;
	cin >> n >> d >> tim;
	for(int i = 1; i <= n; i++)	
	{
		cin >> t[i];
	}
	for(int i = 1; i <= n; i++)
	{ 
		for(int j = i; j >= 1; j--)
		{
			if(t[j]+i-j <= tim)
			{
				lst[i] = j;
				break;
			}
		}
		o[i].push_back(lst[i]);
		for(auto it : o[i-1])	o[i].push_back(it);
		sort(o[i].begin(), o[i].end());
	}
	d = min(n, d);
	t[0] = 1e18;
	memset(dp, 0x3f, sizeof(dp));
	// for(int i = 1; i <= n; i++)
	// {
		// for(int j = 1; j <= n; j++)
		// {
			// if(j < i)	cout << "0 ";
			// else	cout << C(i, j) << ' ';
		// }
		// cout << '\n';
	// }
	// cout << '\n';
	dp[0][d] = 0;
	for(int i = 1; i <= n; i++)	dp[i][d] = C(1, i);
	for(int i = 1; i <= n; i++)
	{
		for(int j = 0; j < d; j++)
		{
			for(int k = i-1; k >= 0; k--)
			{
				dp[i][j] = min(dp[k][j+1]+C(k+1, i), dp[i][j]);
			}
		}
	}
	lg ans = n+1;
	for(int j = 0; j <= d; j++)
	{
		ans = min(ans, dp[n][j]);
	}
	cout << ans << '\n';
}
#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...