Submission #683481

# Submission time Handle Problem Language Result Execution time Memory
683481 2023-01-18T14:01:58 Z nifeshe Skyline (IZhO11_skyline) C++17
100 / 100
314 ms 222536 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment (linker, "/STACK: 16777216")

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define int long long

using namespace std;
using namespace __gnu_pbds;

template <typename T> inline bool umax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

ll mod = 998244353;
const ll base = 1e6 + 5;
const ll inf = 1e18;
const int MAX = 300 + 5;
const int lg = 20;

random_device rd;
mt19937 gen(rd());
uniform_int_distribution<ll> dis(1, inf);

int dp[MAX][MAX][MAX];

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &i : a) {
        cin >> i;
    }
    if(n == 1) {
        cout << a[0] * 3 << '\n';
        return;
    }
    for(int i = 0; i < MAX; i++) {
        for(int j = 0; j < MAX; j++) {
            for(int k = 0; k < MAX; k++) {
                dp[i][j][k] = inf;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < MAX; j++) {
            for(int k = 0; k < MAX; k++) {
                if(j == a[i]) umin(dp[i + 1][k][0], dp[i][j][k]);
                if(j + 1 < MAX) umin(dp[i][j + 1][k], dp[i][j][k] + 3);
                if(k + 1 < MAX) umin(dp[i][j][k + 1], dp[i][j][k] + 3);
                if(j + 1 < MAX && k + 1 < MAX) umin(dp[i][j + 1][k + 1], dp[i][j][k] + 5);
                if(j < a[i] && k + (a[i] - j) < MAX) umin(dp[i + 1][k + (a[i] - j)][(a[i] - j)], dp[i][j][k] + 7 * (a[i] - j));
            }
        }
    }
    cout << dp[n][0][0] << '\n';
}

signed main() {
//    freopen("skyline.in", "r", stdin); freopen("skyline.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ttt = 1;
//    cin >> ttt;
    while(ttt--) {
        solve();
    }
    return 0;
}

Compilation message

skyline.cpp:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    8 | #pragma comment (linker, "/STACK: 16777216")
      |
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 84 ms 222316 KB Output is correct
3 Correct 88 ms 222432 KB Output is correct
4 Correct 103 ms 222400 KB Output is correct
5 Correct 83 ms 222404 KB Output is correct
6 Correct 85 ms 222296 KB Output is correct
7 Correct 94 ms 222300 KB Output is correct
8 Correct 92 ms 222288 KB Output is correct
9 Correct 93 ms 222320 KB Output is correct
10 Correct 100 ms 222356 KB Output is correct
11 Correct 149 ms 222400 KB Output is correct
12 Correct 96 ms 222280 KB Output is correct
13 Correct 150 ms 222324 KB Output is correct
14 Correct 179 ms 222396 KB Output is correct
15 Correct 242 ms 222356 KB Output is correct
16 Correct 230 ms 222404 KB Output is correct
17 Correct 286 ms 222376 KB Output is correct
18 Correct 295 ms 222536 KB Output is correct
19 Correct 264 ms 222312 KB Output is correct
20 Correct 314 ms 222284 KB Output is correct