답안 #588251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588251 2022-07-02T21:29:13 Z inluminas 스카이라인 (IZhO11_skyline) C++17
100 / 100
105 ms 50656 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)));
vector<vector<int>> sev (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=0;j<202;j++) fill(sev[j].begin(),sev[j].end(),1e9);

		for(int j=h[i-1];j>=0;j--){
			for(int k=h[i-1]-j;k>=0;k--){
				sev[j][k]=min(dp[i-1][h[i-1]-j-k][j],min(sev[j+1][k],sev[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],sev[j][k]+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 50508 KB Output is correct
2 Correct 40 ms 50620 KB Output is correct
3 Correct 37 ms 50504 KB Output is correct
4 Correct 40 ms 50592 KB Output is correct
5 Correct 39 ms 50580 KB Output is correct
6 Correct 42 ms 50508 KB Output is correct
7 Correct 38 ms 50512 KB Output is correct
8 Correct 40 ms 50624 KB Output is correct
9 Correct 37 ms 50584 KB Output is correct
10 Correct 40 ms 50564 KB Output is correct
11 Correct 46 ms 50616 KB Output is correct
12 Correct 39 ms 50616 KB Output is correct
13 Correct 48 ms 50580 KB Output is correct
14 Correct 52 ms 50528 KB Output is correct
15 Correct 78 ms 50560 KB Output is correct
16 Correct 79 ms 50544 KB Output is correct
17 Correct 99 ms 50620 KB Output is correct
18 Correct 96 ms 50620 KB Output is correct
19 Correct 94 ms 50656 KB Output is correct
20 Correct 105 ms 50616 KB Output is correct