답안 #169602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169602 2019-12-21T11:40:53 Z SamAnd 스카이라인 (IZhO11_skyline) C++17
0 / 100
3 ms 1400 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 303, INF = 1000000009;

int n;
int a[N];

int dp[N][N][N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    if (n == 1)
    {
        printf("%d\n", a[1] * 3);
        return 0;
    }
    for (int i = 0; i <= n; ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            for (int k = 0; k < N; ++k)
            {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[2][a[1]][a[2]] = 0;
    for (int i = 2; i <= n; ++i)
    {
        for (int j = N - 1; j >= 0; --j)
        {
            for (int k = N - 1; k >= 0; --k)
            {
                if (k > 0)
                    dp[i][j][k - 1] = min(dp[i][j][k - 1], dp[i][j][k] + 3);
                if (k > 0 && j > 0)
                    dp[i][j - 1][k - 1] = min(dp[i][j - 1][k - 1], dp[i][j][k] + 5);
            }
        }
        if (i == n)
            break;
        for (int j = 0; j < N; ++j)
        {
            for (int k = 0; k < N; ++k)
            {
                if (a[i + 1] >= j && k >= j)
                {
                    dp[i + 1][k - j][a[i + 1] - j] = min(dp[i + 1][k - j][a[i + 1] - j], dp[i][j][k] + j * 7);
                }
            }
        }
    }
    printf("%d\n", dp[n][0][0]);
    return 0;
}

Compilation message

skyline.cpp: In function 'int main()':
skyline.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
skyline.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 3 ms 1400 KB Output isn't correct
3 Halted 0 ms 0 KB -