Submission #963217

# Submission time Handle Problem Language Result Execution time Memory
963217 2024-04-14T18:24:08 Z biank Skyline (IZhO11_skyline) C++14
100 / 100
101 ms 165024 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 305;

using ll = long long;

const ll INF = 1e18;

ll dp[MAX_N][MAX_N][MAX_N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n;
    cin >> n;
    vector<int> h(n + 2);
    for (int i = 2; i < n + 2; i++) {
        cin >> h[i];
    }
    for (int i = 2; i < n + 2; i++) {
        for (int j = 0; j <= h[i - 1]; j++) {
            for (int k = 0; k <= h[i]; k++) {
                dp[i][j][k] = INF;
                if (k != 0) dp[i][j][k] = min(dp[i][j][k], dp[i][j][k - 1] + 3LL);
                if (j != 0 && k != 0) dp[i][j][k] = min(dp[i][j][k], dp[i][j - 1][k - 1] + 5LL);
                if (j >= k && h[i - 2] >= k) dp[i][j][k] = min(dp[i][j][k], dp[i - 1][h[i - 2] - k][j - k] + 7LL * k);
            }
        }
    }
    cout << dp[n + 1][h[n]][h[n + 1]] << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 19 ms 53596 KB Output is correct
5 Correct 2 ms 6488 KB Output is correct
6 Correct 2 ms 8540 KB Output is correct
7 Correct 1 ms 8536 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 3 ms 12636 KB Output is correct
10 Correct 4 ms 18780 KB Output is correct
11 Correct 20 ms 75608 KB Output is correct
12 Correct 5 ms 24924 KB Output is correct
13 Correct 25 ms 80388 KB Output is correct
14 Correct 29 ms 92244 KB Output is correct
15 Correct 75 ms 139904 KB Output is correct
16 Correct 69 ms 129244 KB Output is correct
17 Correct 101 ms 164692 KB Output is correct
18 Correct 97 ms 162132 KB Output is correct
19 Correct 90 ms 154968 KB Output is correct
20 Correct 100 ms 165024 KB Output is correct