답안 #400242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400242 2021-05-07T17:56:57 Z kgh3620 스카이라인 (IZhO11_skyline) C++17
컴파일 오류
0 ms 0 KB
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>
 
using namespace std;
 
int h[301];
int dp[305][205][205];
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int n;
 
	cin >> n;
 
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
  	
  	if(n==1)
    {
      cout << 3*h[0] << '\n';
      return 0;
    }
  	else if(n==2)
    {
      int x = min(h[0].h[1]);
      cout << 5*x + (h[0]-x)*3 + (h[1]-x)*3 << '\n';
      return 0;
    }
 
	for(int i=0;i<=300;i++)
	{
		for (int j = 0; j <= 200; j++)
		{
			for (int k = 0; k <= 200; k++)
			{
				dp[i][j][k] = 1e9;
			}
		}
	}
 
	dp[2][h[0]][h[1]] = 0;
 
	for (int i = 0; i < n + 2; i++)
	{
		for (int j = 0; j <= 200; j++)
		{
			for (int k = 0; k <= 200; k++)
			{
				if (dp[i][j][k] >= 1e9)
				{
					continue;
				}
				int a = j;
				int b = k;
				int c = h[i];
				int m = min(a, min(b, c));
				int cost = 7 * m;
				dp[i + 1][b - m][c - m] = min(dp[i + 1][b - m][c - m], dp[i][a][b] + cost + 3*(a-m));
				int M = min(a - m, b - m);
				int na = a - m - M;
				int nb = b - m - M;
				cost += (5 * M);
				dp[i + 1][nb][c - m] = min(dp[i + 1][nb][c - m], dp[i][a][b] + cost + 3 * na);
				m = min(a, b);
				cost = 5 * m + (a - m) * 3;
				dp[i + 1][b - m][c] = min(dp[i + 1][b - m][c], dp[i][a][b] + cost);
				cost = 3 * a;
				dp[i + 1][b][c] = min(dp[i + 1][b][c], dp[i][a][b] + cost);
			}
		}
	}
 
	int res = 1e9;
 
	cout << dp[n + 2][0][0] << '\n';
 
	return 0;
}

Compilation message

skyline.cpp: In function 'int main()':
skyline.cpp:52:24: error: request for member 'h' in 'h[0]', which is of non-class type 'int'
   52 |       int x = min(h[0].h[1]);
      |                        ^
skyline.cpp:100:6: warning: unused variable 'res' [-Wunused-variable]
  100 |  int res = 1e9;
      |      ^~~