Submission #6879

#TimeUsernameProblemLanguageResultExecution timeMemory
6879gs12117도장 모으기 (JOI14_stamps)C++98
100 / 100
84 ms74996 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...