Submission #683955

#TimeUsernameProblemLanguageResultExecution timeMemory
683955KiriLL1caSkyline (IZhO11_skyline)C++17
100 / 100
179 ms222460 KiB
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define pw(x) (1ll << x)
#define vec vector
#define sz(x) (int)((x).size())
#define forn(i, s, f) for (int i = s; i <= f; ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }

#define int long long

const int N = 305;
const int inf = 1e18 + 7;
int dp[N][N][N], a[N];

inline void solve () {
        int n; cin >> n;
        for (int i = 1; i <= n; ++i) cin >> a[i];
        if (n == 1) { cout << a[1] * 3; return; }
        forn (i, 0, N-1) forn (f, 0, N-1) forn (s, 0, N-1) dp[i][f][s] = inf;

        dp[0][0][0] = 0;
        for (int i = 0; i <= n; ++i) {
                int q = a[i + 1], w = a[i + 2];
                for (int f = 0; f <= q; ++f) {
                        for (int s = 0; s <= w; ++s) {
                                if (f == q) umin(dp[i + 1][s][0], dp[i][f][s]);
                                if (f + 1 <= q) umin(dp[i][f + 1][s], dp[i][f][s] + 3);
                                if (s + 1 <= w) umin(dp[i][f][s + 1], dp[i][f][s] + 3);
                                if (f + 1 <= q && s + 1 <= w) umin(dp[i][f + 1][s + 1], dp[i][f][s] + 5);
                                if (s + q - f <= w) umin(dp[i + 1][s + q - f][q - f], dp[i][f][s] + 7 * (q - f));
                        }
                }
        }
        cout << dp[n + 1][0][0] << endl;
}

signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #ifdef LOCAL
                freopen("input.txt", "r", stdin);
                freopen("output.txt", "w", stdout);
        #endif
        int t = 1; // cin >> t;
        while (t--) solve();
        return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...