# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163197 | TadijaSebez | 도장 모으기 (JOI14_stamps) | C++11 | 199 ms | 72184 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3050;
const ll inf=3e18;
ll dp[N][N];
int U[N],V[N],D[N],E[N];
int main()
{
int n,t;
scanf("%i %i",&n,&t);
for(int i=1;i<=n;i++) scanf("%i %i %i %i",&U[i],&V[i],&D[i],&E[i]);
dp[0][0]=0;
for(int i=1;i<=n;i++) dp[0][i]=inf;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
dp[i][j]=inf;
if(j!=0) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+D[i]+V[i]-t*i*2);
if(j!=n) dp[i][j]=min(dp[i][j],dp[i-1][j+1]+U[i]+E[i]+t*i*2);
dp[i][j]=min(dp[i][j],dp[i-1][j]+U[i]+V[i]);
if(j!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+D[i]+E[i]);
}
for(int j=1;j<=n;j++) dp[i][j]=min(dp[i][j],dp[i][j-1]+D[i]+V[i]-t*i*2);
for(int j=n-1;j>=1;j--) dp[i][j]=min(dp[i][j],dp[i][j+1]+U[i]+E[i]+t*i*2);
}
ll ans=dp[n][0]+(n+1)*t;
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |