Submission #868253

#TimeUsernameProblemLanguageResultExecution timeMemory
868253lmToT27Holding (COCI20_holding)C++14
0 / 110
68 ms262144 KiB
#include <bits/stdc++.h>
using namespace std;
long long dpL[102][102][2502], dpR[102][102][2502], ans = 1e18, tong;
int n, a[102], L, R, K;
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);
    }
    memset(dpL, 0x1, sizeof dpL);
    memset(dpR, 0x1, sizeof dpR);
    cin >> n >> L >> R >> K;
    K = min(K, n * n / 4);
    dpL[L][L - 1][0] = 0;
    dpR[R + 1][R][0] = 0;
    for (int i = 1; i <= n; i++)
        cin >> a[i], tong += a[i];
    for (int i = L; i <= R; i++) {
        for (int j = L; j >= 1; j--) {
            for (int TIME = 0; TIME <= K; TIME++) {
                dpL[j][i][TIME] = min(dpL[j + 1][i][TIME], dpL[j][i - 1][TIME] + a[i]);
                if (TIME - i + j >= 0)
                    dpL[j][i][TIME] = min(dpL[j][i][TIME], dpL[j + 1][i - 1][   TIME - i + j] + a[j]);
            }
        }
    }
    for (int i = R; i >= L; i--) {
        for (int j = R; j <= n; j++) {
            for (int TIME = 0; TIME <= K; TIME++) {
                dpR[i][j][TIME] = min(dpR[i][j - 1][TIME], dpR[i + 1][j][TIME] + a[i]);
                if (TIME - j + i >= 0)
                    dpR[i][j][TIME] = min(dpR[i][j][TIME], dpR[i + 1][j - 1][TIME - j + i] + a[j]);
            }
        }
    }
    for (int TIME = 0; TIME <= K; TIME++)
    dpL[1][L - 1][TIME] = dpR[R + 1][n][TIME] = 0;
    for (int i = L - 1; i <= R; i++)
        for (int TIME = 0; TIME <= K; TIME++)
            ans = min(ans, dpL[1][i][TIME] + dpR[i + 1][n][K - TIME]);
    cout << ans;
    return 0;
}

Compilation message (stderr)

holding.cpp: In function 'int main()':
holding.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen("TASK.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         freopen("TASK.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...