Submission #874454

# Submission time Handle Problem Language Result Execution time Memory
874454 2023-11-17T04:37:58 Z The_Samurai Skyline (IZhO11_skyline) C++17
100 / 100
97 ms 50008 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;
    if (n == 1) {
        cout << a[0] * 3;
        return;
    }
    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 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 856 KB Output is correct
3 Correct 1 ms 1216 KB Output is correct
4 Correct 17 ms 12184 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 3 ms 2140 KB Output is correct
7 Correct 2 ms 1884 KB Output is correct
8 Correct 2 ms 1624 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 6 ms 4360 KB Output is correct
11 Correct 41 ms 23900 KB Output is correct
12 Correct 9 ms 5464 KB Output is correct
13 Correct 48 ms 28036 KB Output is correct
14 Correct 59 ms 33372 KB Output is correct
15 Correct 88 ms 45660 KB Output is correct
16 Correct 89 ms 41060 KB Output is correct
17 Correct 96 ms 50008 KB Output is correct
18 Correct 96 ms 49844 KB Output is correct
19 Correct 93 ms 48024 KB Output is correct
20 Correct 97 ms 50008 KB Output is correct