Submission #1024087

# Submission time Handle Problem Language Result Execution time Memory
1024087 2024-07-15T11:43:23 Z AeonARY Holding (COCI20_holding) C++17
55 / 110
23 ms 119644 KB
#include <bits/stdc++.h>
using namespace std;

#define Task "HOLDING"
#define ll long long
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)

const int N = 1e6 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;

template<class X, class Y>
    bool minimize(X &x, Y y) {
        if (x > y) {
            x = y;
            return true;
        } else return false;
    }

template<class X, class Y>
    bool maximize(X &x, Y y) {
        if (x < y) {
            x = y;
            return true;
        } else return false;
    }

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

namespace sub2 {
    int dp[55][55][10004];

    void solve() {
        memset(dp, 0, sizeof(dp));
        FOR(i, 1, l - 1) FOR(j, l, r) FOR(h, 0, k) {
            dp[i][j][h] = max(dp[i - 1][j][h], dp[i][j - 1][h]);
            int cost = j - i;
            if (h >= cost)
                maximize(dp[i][j][h], dp[i - 1][j - 1][h - cost] + a[j] - a[i]);
        }
        int sum = 0, sub = 0;
        FOR(i, l, r) sum += a[i];
        FOR(i, 1, l - 1) FOR(h, 0, k) maximize(sub, dp[i][n][h]);
        cout << sum - sub;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(Task".INP", "r")) {
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }

    cin >> n >> l >> r >> k;
    FOR(i, 1, n) cin >> a[i];

    if (n <= 50 && r == n) sub2::solve();

    return 0;
}


Compilation message

holding.cpp: In function 'int main()':
holding.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(Task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(Task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 119640 KB Output is correct
2 Correct 14 ms 119644 KB Output is correct
3 Correct 14 ms 119644 KB Output is correct
4 Correct 15 ms 119608 KB Output is correct
5 Correct 16 ms 119636 KB Output is correct
6 Correct 14 ms 119644 KB Output is correct
7 Correct 15 ms 119644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 119640 KB Output is correct
2 Correct 14 ms 119644 KB Output is correct
3 Correct 14 ms 119644 KB Output is correct
4 Correct 15 ms 119608 KB Output is correct
5 Correct 16 ms 119636 KB Output is correct
6 Correct 14 ms 119644 KB Output is correct
7 Correct 15 ms 119644 KB Output is correct
8 Correct 15 ms 119644 KB Output is correct
9 Correct 14 ms 119644 KB Output is correct
10 Correct 15 ms 119644 KB Output is correct
11 Correct 15 ms 119644 KB Output is correct
12 Correct 13 ms 119644 KB Output is correct
13 Correct 23 ms 119600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 119640 KB Output is correct
2 Correct 14 ms 119644 KB Output is correct
3 Correct 14 ms 119644 KB Output is correct
4 Correct 15 ms 119608 KB Output is correct
5 Correct 16 ms 119636 KB Output is correct
6 Correct 14 ms 119644 KB Output is correct
7 Correct 15 ms 119644 KB Output is correct
8 Correct 15 ms 119644 KB Output is correct
9 Correct 14 ms 119644 KB Output is correct
10 Correct 15 ms 119644 KB Output is correct
11 Correct 15 ms 119644 KB Output is correct
12 Correct 13 ms 119644 KB Output is correct
13 Correct 23 ms 119600 KB Output is correct
14 Incorrect 1 ms 2396 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 119640 KB Output is correct
2 Correct 14 ms 119644 KB Output is correct
3 Correct 14 ms 119644 KB Output is correct
4 Correct 15 ms 119608 KB Output is correct
5 Correct 16 ms 119636 KB Output is correct
6 Correct 14 ms 119644 KB Output is correct
7 Correct 15 ms 119644 KB Output is correct
8 Correct 15 ms 119644 KB Output is correct
9 Correct 14 ms 119644 KB Output is correct
10 Correct 15 ms 119644 KB Output is correct
11 Correct 15 ms 119644 KB Output is correct
12 Correct 13 ms 119644 KB Output is correct
13 Correct 23 ms 119600 KB Output is correct
14 Incorrect 1 ms 2396 KB Output isn't correct
15 Halted 0 ms 0 KB -