답안 #588243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588243 2022-07-02T21:15:36 Z inluminas 스카이라인 (IZhO11_skyline) C++17
0 / 100
38 ms 50596 KB
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define inf LLONG_MAX
#define fastio ios_base::sync_with_stdio(false)
#define endl "\n"
#define l first
#define r second

vector<vector<vector<int> > > dp (302,vector<vector<int>>(202,vector<int>(202,1e9)));

int main(){
	fastio;

	int n; cin>>n;
	int h[n+1];
	for(int i=1;i<=n;i++)  cin>>h[i];

	dp[1][0][0]=h[1]*3;
	
	for(int i=2;i<=n;i++){
		for(int j=1;j<=h[i-1];j++){
			for(int k=h[i-1]-j;k>=0;k--){
				dp[i-1][j][k]=min(dp[i-1][j][k],min(dp[i-1][j-1][k],dp[i-1][j][k+1]));
			}
		}

		for(int j=0;j<=h[i];j++){
			for(int k=0;k<=h[i]-j;k++){
				int l=h[i]-j-k;
				if(h[i-1]-j-k<0) continue;
				dp[i][j][k]=min(dp[i][j][k],dp[i-1][h[i-1]-j-k][j]+2*j+2*k+3*l);
			}
		}
	}

	int ans=1e9;

	for(int j=0;j<=h[n];j++) for(int k=0;k<=h[n]-j;k++){
		ans=min(ans,dp[n][j][k]);
	}

	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 50596 KB Output is correct
2 Correct 36 ms 50580 KB Output is correct
3 Incorrect 37 ms 50592 KB Output isn't correct
4 Halted 0 ms 0 KB -