답안 #869857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869857 2023-11-06T02:32:41 Z prohacker Holding (COCI20_holding) C++14
110 / 110
28 ms 30196 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

const int N = 105;
const int INF = INT_MAX;
const int mod = 1e9+7;

int n,m,l,r;
int a[N];
int ans,dp[N][N][3005],f[N][N][3005],sum;

signed main()
{
    if (fopen("DEBT.inp", "r")) {
        freopen("DEBT.inp", "r", stdin);
        freopen("DEBT.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> l >> r >> m;
    m = min(m,3000);
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        if(l <= i and i <= r) {
            sum += a[i];
        }
    }
    for(int i = 1 ; i < l ; i++) {
        for(int j = l ; j <= r ; j++) {
            for(int k = 0 ; k <= m ; k++) {
                dp[i][j][k] = max(dp[i][j][k],dp[i-1][j][k]);
                dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k]);
                if(k >= j-i) {
                    dp[i][j][k] = max(dp[i][j][k],dp[i-1][j-1][k-j+i]+a[j]-a[i]);
                }
            }
        }
    }
    for(int i = n ; i > r ; i--) {
        for(int j = r ; j >= l ; j--) {
            for(int k = 0 ; k <= m ; k++) {
                f[j][i][k] = max(f[j][i][k],f[j][i+1][k]);
                f[j][i][k] = max(f[j][i][k],f[j+1][i][k]);
                if(k >= i-j) {
                    f[j][i][k] = max(f[j][i][k],f[j+1][i+1][k+j-i]+a[j]-a[i]);
                }
            }
        }
    }
    int ans = 0;
    ans = max(dp[l-1][r][m],f[l][r+1][m]);
    for(int i = l ; i < r ; i++) {
        for(int k = 0 ; k <= m ; k++) {
            ans = max(ans,dp[l-1][i][k]+f[i+1][r+1][m-k]);
        }
    }
    cout << sum-ans;
    return 0;
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("DEBT.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("DEBT.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 3160 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 1 ms 2140 KB Output is correct
13 Correct 7 ms 7784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 3160 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 1 ms 2140 KB Output is correct
13 Correct 7 ms 7784 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 7 ms 7872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 856 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 2 ms 3160 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 1 ms 2140 KB Output is correct
13 Correct 7 ms 7784 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Correct 1 ms 1884 KB Output is correct
18 Correct 2 ms 2908 KB Output is correct
19 Correct 7 ms 7872 KB Output is correct
20 Correct 4 ms 6480 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 3 ms 3164 KB Output is correct
24 Correct 7 ms 12124 KB Output is correct
25 Correct 28 ms 30196 KB Output is correct