이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |