Submission #6082

#TimeUsernameProblemLanguageResultExecution timeMemory
6082ainta도장 모으기 (JOI14_stamps)C++98
100 / 100
112 ms71916 KiB
#include<stdio.h> int n, T; int w[3010][4]; long long D[3010][3010]; int main() { int i, j, g, h; long long M; scanf("%d%d",&n,&T); for(i=1;i<=n;i++){ scanf("%d%d%d%d",&w[i][0],&w[i][1],&w[i][2],&w[i][3]); } for(i=0;i<=n;i++){ for(j=0;j<n;j++){ D[i][j] = 21000000000000000LL; } } D[0][0] = T; for(i=1;i<=n;i++){ g=w[i][2]+w[i][1]; h=w[i][0]+w[i][1]; for(j=0;j<n;j++){ if(j && D[i][j] > M + (2*j+1)*T)D[i][j] = M + (2*j+1)*T; if(D[i][j] > D[i-1][j] + h + (2*j+1)*T)D[i][j] = D[i-1][j] + h + (2*j+1)*T; if(j == 0 || M > D[i-1][j]) M = D[i-1][j]; M += g; } g=w[i][0]+w[i][3]; h=w[i][2]+w[i][3]; for(j=n-1;j>=0;j--){ if(j != n-1 && D[i][j] > M + (2*j+1)*T)D[i][j] = M + (2*j+1)*T; if(j && D[i][j] > D[i-1][j] + h + (2*j+1)*T)D[i][j] = D[i-1][j] + h + (2*j+1)*T; if(j == n-1 || M > D[i-1][j]) M = D[i-1][j]; M += g; } } printf("%lld\n",D[n][0]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...