Submission #874453

# Submission time Handle Problem Language Result Execution time Memory
874453 2023-11-17T04:37:17 Z The_Samurai Skyline (IZhO11_skyline) C++17
0 / 100
1 ms 1044 KB
// #pragma GCC optimize("Ofast,O3")
// #pragma GCC target("avx,avx2")
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int inf = 1e6;
const int N = 201;

void mins(int &a, int b) {
    a = min(a, b);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &x: a) cin >> x;
    vector dp(n, vector(N, vector(N, inf)));
    dp[0][a[0]][a[1]] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int v1 = N - 1; v1 >= 0; v1--) {
            for (int v2 = N - 1; v2 >= 0; v2--) {
                if (v1 > 0) mins(dp[i][v1 - 1][v2], dp[i][v1][v2] + 3);
                if (v2 > 0) mins(dp[i][v1][v2 - 1], dp[i][v1][v2] + 3);
                if (v1 > 0 and v2 > 0) mins(dp[i][v1 - 1][v2 - 1], dp[i][v1][v2] + 5);
                if (i + 2 >= n) continue;
                int mn = min(v1, min(v2, a[i + 2]));
                if (mn == v1) {
                    mins(dp[i + 1][v2 - mn][a[i + 2] - mn], dp[i][v1][v2] + 7 * mn);
                }
            }
        }
    }
    cout << dp[n - 2][0][0];
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1044 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -