이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#define INF 999999999999999LL
int n;
long long int m;
long long int a[100100];
long long int b[100100];
long long int c[100100];
long long int d[100100];
long long int dp[3010][3010];
long long int stp;
int main(){
// freopen("input.txt","r",stdin);
int i,j;
scanf("%d%lld",&n,&m);
dp[0][0]=m;
for(i=1;i<=n;i++){
dp[0][i]=INF;
}
stp=INF;
for(i=0;i<n;i++){
scanf("%lld%lld%lld%lld",&a[i],&b[i],&c[i],&d[i]);
if(stp>b[i]+c[i])stp=b[i]+c[i];
for(j=0;j<n;j++){
dp[i+1][j]=dp[i][j]+a[i]+b[i];
if(dp[i+1][j]>dp[i][j+1]+a[i]+d[i])dp[i+1][j]=dp[i][j+1]+a[i]+d[i];
if(j!=0&&dp[i+1][j]>dp[i][j-1]+b[i]+c[i])dp[i+1][j]=dp[i][j-1]+b[i]+c[i];
if(j!=0&&dp[i+1][j]>dp[i][j]+c[i]+d[i])dp[i+1][j]=dp[i][j]+c[i]+d[i];
if(j!=0&&dp[i+1][j]>dp[i+1][j-1]+stp)dp[i+1][j]=dp[i+1][j-1]+stp;
}
dp[i][n]=INF;
for(j=0;j<n;j++){
dp[i+1][j]+=m*(j*2+1);
}
stp+=2*m;
}
printf("%lld",dp[n][0]);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |