Submission #169603

# Submission time Handle Problem Language Result Execution time Memory
169603 2019-12-21T11:44:08 Z SamAnd Skyline (IZhO11_skyline) C++17
100 / 100
302 ms 108636 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()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    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[1][0][a[1]] = 0;
    for (int i = 1; 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:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
skyline.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 53 ms 25848 KB Output is correct
5 Correct 7 ms 2808 KB Output is correct
6 Correct 9 ms 4216 KB Output is correct
7 Correct 9 ms 3960 KB Output is correct
8 Correct 7 ms 3192 KB Output is correct
9 Correct 12 ms 5368 KB Output is correct
10 Correct 23 ms 9336 KB Output is correct
11 Correct 128 ms 51320 KB Output is correct
12 Correct 29 ms 11512 KB Output is correct
13 Correct 147 ms 60280 KB Output is correct
14 Correct 184 ms 72344 KB Output is correct
15 Correct 268 ms 99192 KB Output is correct
16 Correct 242 ms 89180 KB Output is correct
17 Correct 302 ms 108636 KB Output is correct
18 Correct 300 ms 107896 KB Output is correct
19 Correct 286 ms 103976 KB Output is correct
20 Correct 299 ms 108408 KB Output is correct