Submission #156047

#TimeUsernameProblemLanguageResultExecution timeMemory
156047puppies_and_rainbows도장 모으기 (JOI14_stamps)C++14
100 / 100
175 ms71268 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, t, dp[3005][3005];
int u[3005], v[3005], d[3005], e[3005];

signed main()
{
	cin>>n>>t;
	for(int i=0; i<=n; i++)
	{
		dp[0][i]=100000000000000;
	}
	dp[0][1]=0;
	for(int i=1; i<=n; i++)
	{
		cin>>u[i]>>v[i]>>d[i]>>e[i];
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=n; j++)
		{
			if(j==1)
			{
				dp[i][j]=dp[i-1][j]+u[i]+v[i];
			}
			else
			{
				dp[i][j]=dp[i-1][j]+min(u[i]+v[i], d[i]+e[i]);
			}
		}
		int tomin[3005];
		tomin[0]=1000000000000000;
		tomin[n+1]=1000000000000000;
		for(int j=1; j<=n; j++)
		{
			tomin[j]=min(tomin[j-1], dp[i-1][j]-j*(v[i]+d[i]));
		}
		for(int j=1; j<=n; j++)
		{
			dp[i][j]=min(dp[i][j], tomin[j-1]+j*(v[i]+d[i]));
		}
		for(int j=n; j>=1; j--)
		{
			tomin[j]=min(tomin[j+1], dp[i-1][j]+j*(u[i]+e[i]));
		}
		for(int j=1; j<=n; j++)
		{
			dp[i][j]=min(dp[i][j], tomin[j+1]-j*(u[i]+e[i]));
		}
		for(int j=1; j<=n; j++)
		{
			dp[i][j]+=(2*j-1)*t;
		}
		// for(int j=1; j<=4; j++)
		// {
		// 	cout<<dp[i][j]<<" ";
		// }
		// cout<<endl;
	}
	cout<<dp[n][1]+t;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...