Submission #13341

#TimeUsernameProblemLanguageResultExecution timeMemory
13341baneling100Skyline (IZhO11_skyline)C++98
100 / 100
72 ms1400 KiB
#include <stdio.h> #include <algorithm> #define N_MAX 300 #define H_MAX 200 using namespace std; int N, H[N_MAX+3], D[2][H_MAX+1][H_MAX+1]; int main(void) { int i, j, k, now, prev; scanf("%d",&N); for(i=1 ; i<=N ; i++) scanf("%d",&H[i]); for(i=0 ; i<=H[1] ; i++) for(j=0 ; j<=H[2] ; j++) D[0][i][j]=5*min(i,j)+3*(max(i,j)-min(i,j)); for(i=1 ; i<=N ; i++) { now=i%2; prev=(i-1)%2; for(j=0 ; j<=H[i+1] ; j++) { D[now][j][0]=D[prev][H[i]][j]; for(k=1 ; k<=H[i+2] ; k++) { D[now][j][k]=D[now][j][k-1]+3; if(j) D[now][j][k]=min(D[now][j][k],D[now][j-1][k-1]+5); if(H[i]>=k && j>=k) D[now][j][k]=min(D[now][j][k],D[prev][H[i]-k][j-k]+7*k); } } } printf("%d",D[N%2][0][0]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...