101062024-03-26 22:08:53szilJancsi és Juliska kitalálós játékacpp17Wrong answer 94/100564ms5212 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 302;

int f[MAXN], dp[MAXN][MAXN], opt[MAXN][MAXN];

void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> f[i];
    }

    for (int i = 1; i <= n; i++) {
        opt[i][i] = i;
        for (int j = 1; j <= n; j++) {
            if (i >= j) dp[i][j] = 0;
            else dp[i][j] = 1e9;
        }
    }
    for (int i = n; i >= 1; i--) {
        for (int j = i+1; j <= n; j++) {
            for (int z = max(i, opt[i][j-1]-20); z <= j; z++) {
                int maxe = 0;
                for (int y = z; y <= j; y++) {
                    maxe = max(maxe, f[y]);
                    // if (i == 1 && j == 7) cerr << z << " " << y << " " << dp[i][z-1] << " " << dp[z][y] << " " << dp[y+1][j] << " " << get_max(z, y) << endl;
                    ll val = max(dp[i][z-1], max(dp[z][y], dp[y+1][j])) + maxe;
                    if (dp[i][j] > val) {
                        dp[i][j] = val;
                        opt[i][j] = z;
                    }
                }
            }
        }
    }
    /*cerr << opt[1][8] << endl;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }*/
    cout << dp[1][n] << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base94/100
1Accepted0/03ms1916 KiB
2Accepted0/0228ms3576 KiB
3Accepted4/43ms2208 KiB
4Accepted5/53ms2492 KiB
5Accepted5/53ms2800 KiB
6Accepted5/53ms2848 KiB
7Accepted5/512ms3272 KiB
8Accepted5/512ms3312 KiB
9Accepted5/521ms3476 KiB
10Accepted5/528ms3900 KiB
11Accepted5/550ms4116 KiB
12Accepted5/582ms4276 KiB
13Accepted5/571ms4556 KiB
14Accepted5/575ms4724 KiB
15Accepted5/5174ms4984 KiB
16Accepted5/5122ms4932 KiB
17Accepted5/5301ms4956 KiB
18Accepted5/5423ms5212 KiB
19Accepted5/5194ms4980 KiB
20Accepted5/5564ms5000 KiB
21Accepted5/5266ms4900 KiB
22Wrong answer0/6361ms4896 KiB