Submission #960218

#TimeUsernameProblemLanguageResultExecution timeMemory
960218IsamSkyline (IZhO11_skyline)C++17
100 / 100
110 ms55376 KiB
#include<bits/stdc++.h>
using namespace std;

constexpr int inf = 1E9;

int n, h[305], dp[305][205][205];

int f(int i, int x, int y){
	
	if(i == n + 1) return 0;
	
	if(dp[i][x][y]) return dp[i][x][y];
	
	int res = inf;
	
	if(!x) res = f(i + 1, y, h[i+2]);
	else{
		
		res = min(res, f(i, x - 1, y) + 3);
		
		if(y){
			
			res = min(res, f(i, x - 1, y - 1) + 5);
			
			if(x <= min(y, h[i + 2])) res = min(res, f(i + 1, y - x, h[i + 2] - x) + 7 * x);
			
		}
		
	}
	
	return dp[i][x][y] = res;
	
}



signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	register int j(1);
	loop:
		cin >> h[j++];
	if(j <= n) goto loop;
	
	cout << f(1, h[1], h[2]) << '\n';
	
	return 0;
}

Compilation message (stderr)

skyline.cpp: In function 'int main()':
skyline.cpp:40:15: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   40 |  register int j(1);
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...