Submission #1075632

# Submission time Handle Problem Language Result Execution time Memory
1075632 2024-08-26T08:10:07 Z tradz Holding (COCI20_holding) C++14
55 / 110
108 ms 204584 KB
#include <bits/stdc++.h>

#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())

using namespace std;
const int  N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;

int n, l, r, k;
int a[N];

int dpL[102][102][2507];
int dpR[102][102][2507];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    #define TASK ""
    if (fopen (".inp", "r")) {
        freopen (".inp", "r", stdin);
        freopen (".out", "w", stdout);
    }
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    cin >> n >> l >> r >> k;
    memset(dpL, 0, sizeof dpL);
    memset(dpR, 0, sizeof dpR);
    For (i, 1, n) cin >> a[i];
    k = min(k, n * n / 4);
    int sum = 0;
    for (int i = l; i <= r; i++) sum += a[i];
    for (int i = 1; i < l; i++) {
        for (int j = l; j <= r; j++) {
            for (int h = 0; h <= k; h++) {
                dpL[i][j][h] = max(dpL[i - 1][j][h], dpL[i][j - 1][h]);
                if (h >= (j - i)) dpL[i][j][h] = max(dpL[i][j][h], dpL[i - 1][j - 1][h - j + i] + a[j] - a[i]);
            }
        }
    }

    for (int i = n; i > r; i--) {
        for (int j = r; j >= l; j--) {
            for (int h = 0; h <= k; h++) {
                dpR[j][i][h] = max(dpR[j + 1][i][h], dpR[j][i + 1][h]);
                if (h >= (i - j)) dpR[j][i][h] = max(dpR[j][i][h], dpR[j + 1][i + 1][k - i + j] + a[j] - a[i]);
            }
        }
    }

    int ans = 0;
    ans = max(dpL[l - 1][r][k], dpR[l][r + 1][k]);
    for (int i = l; i <= r; i++) {
        for (int h = 0; h <= k; h++) {
            ans = max(ans, dpL[l - 1][i][h] + dpR[i + 1][r + 1][k - h]);
        }
    }

    cout << sum - ans << '\n';

    return 0;
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:28:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
holding.cpp:29:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
holding.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 94 ms 204584 KB Output is correct
2 Correct 87 ms 204372 KB Output is correct
3 Correct 93 ms 204372 KB Output is correct
4 Correct 91 ms 204428 KB Output is correct
5 Correct 108 ms 204372 KB Output is correct
6 Correct 84 ms 204428 KB Output is correct
7 Correct 94 ms 204372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 204584 KB Output is correct
2 Correct 87 ms 204372 KB Output is correct
3 Correct 93 ms 204372 KB Output is correct
4 Correct 91 ms 204428 KB Output is correct
5 Correct 108 ms 204372 KB Output is correct
6 Correct 84 ms 204428 KB Output is correct
7 Correct 94 ms 204372 KB Output is correct
8 Correct 87 ms 204376 KB Output is correct
9 Correct 95 ms 204372 KB Output is correct
10 Correct 91 ms 204372 KB Output is correct
11 Correct 99 ms 204552 KB Output is correct
12 Correct 93 ms 204368 KB Output is correct
13 Correct 95 ms 204364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 204584 KB Output is correct
2 Correct 87 ms 204372 KB Output is correct
3 Correct 93 ms 204372 KB Output is correct
4 Correct 91 ms 204428 KB Output is correct
5 Correct 108 ms 204372 KB Output is correct
6 Correct 84 ms 204428 KB Output is correct
7 Correct 94 ms 204372 KB Output is correct
8 Correct 87 ms 204376 KB Output is correct
9 Correct 95 ms 204372 KB Output is correct
10 Correct 91 ms 204372 KB Output is correct
11 Correct 99 ms 204552 KB Output is correct
12 Correct 93 ms 204368 KB Output is correct
13 Correct 95 ms 204364 KB Output is correct
14 Correct 108 ms 204516 KB Output is correct
15 Correct 87 ms 204372 KB Output is correct
16 Incorrect 95 ms 204372 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 204584 KB Output is correct
2 Correct 87 ms 204372 KB Output is correct
3 Correct 93 ms 204372 KB Output is correct
4 Correct 91 ms 204428 KB Output is correct
5 Correct 108 ms 204372 KB Output is correct
6 Correct 84 ms 204428 KB Output is correct
7 Correct 94 ms 204372 KB Output is correct
8 Correct 87 ms 204376 KB Output is correct
9 Correct 95 ms 204372 KB Output is correct
10 Correct 91 ms 204372 KB Output is correct
11 Correct 99 ms 204552 KB Output is correct
12 Correct 93 ms 204368 KB Output is correct
13 Correct 95 ms 204364 KB Output is correct
14 Correct 108 ms 204516 KB Output is correct
15 Correct 87 ms 204372 KB Output is correct
16 Incorrect 95 ms 204372 KB Output isn't correct
17 Halted 0 ms 0 KB -