답안 #870818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870818 2023-11-09T08:15:09 Z hungnt Holding (COCI20_holding) C++14
88 / 110
34 ms 110832 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 105;

int n, L, R, k, s;
int a[102];
int dp[N][2505][N], Left[N][2505], Right[N][2505];

void MAX(int &A, int B)
{
    if(A < B) A = B;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> L >> R >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = L; i <= R; i++) s += a[i];
    k = min(k, n * n / 4);
    int ans = 0;
    for(int i = L; i <= R; i++)
        for(int j = L - 1; j > 0; j--)
            for(int c = 1; c <= k; c++)
            {
                MAX(dp[i][c][j], dp[i - 1][c][j]);
                MAX(dp[i][c][j], dp[i][c][j + 1]);
                if(c - i + j >= 0)
                    MAX(dp[i][c][j], dp[i - 1][c - i + j][j + 1] + a[i] - a[j]);
            }
    for(int i = L; i <= R; i++)
        for(int j = 1; j <= k; j++)
        {
            Left[i][j] = dp[i][j][1];
//            MAX(Left[i][j], Left[i][j - 1]);
        }
    memset(dp, 0, sizeof dp);
    for(int i = R; i >= L; i--)
        for(int j = R + 1; j <= n; j++)
        {
            for(int c = 1; c <= k; c++)
            {
                MAX(dp[i][c][j], dp[i + 1][c][j]);
                MAX(dp[i][c][j], dp[i][c][j - 1]);
                if(c + i - j >= 0)
                    MAX(dp[i][c][j], dp[i + 1][c - i + j][j - 1] + a[i] - a[j]);
            }
        }
    for(int i = R; i >= L; i--)
        for(int j = 1; j <= k; j++)
        {
            Right[i][j] = dp[i][j][n];
//            MAX(Right[i][j], Right[i][j - 1]);
        }
    for(int i = L - 1; i <= R; i++)
        for(int j = 0; j <= k; j++)
            MAX(ans, Left[i][j] + Right[i + 1][k - j]);
    cout << s - ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 110160 KB Output is correct
2 Correct 18 ms 110428 KB Output is correct
3 Correct 19 ms 110384 KB Output is correct
4 Correct 18 ms 110428 KB Output is correct
5 Correct 18 ms 110424 KB Output is correct
6 Correct 18 ms 110424 KB Output is correct
7 Correct 19 ms 110832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 110160 KB Output is correct
2 Correct 18 ms 110428 KB Output is correct
3 Correct 19 ms 110384 KB Output is correct
4 Correct 18 ms 110428 KB Output is correct
5 Correct 18 ms 110424 KB Output is correct
6 Correct 18 ms 110424 KB Output is correct
7 Correct 19 ms 110832 KB Output is correct
8 Correct 20 ms 110428 KB Output is correct
9 Correct 20 ms 110424 KB Output is correct
10 Correct 23 ms 110172 KB Output is correct
11 Correct 25 ms 110440 KB Output is correct
12 Correct 28 ms 110464 KB Output is correct
13 Correct 25 ms 110172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 110160 KB Output is correct
2 Correct 18 ms 110428 KB Output is correct
3 Correct 19 ms 110384 KB Output is correct
4 Correct 18 ms 110428 KB Output is correct
5 Correct 18 ms 110424 KB Output is correct
6 Correct 18 ms 110424 KB Output is correct
7 Correct 19 ms 110832 KB Output is correct
8 Correct 20 ms 110428 KB Output is correct
9 Correct 20 ms 110424 KB Output is correct
10 Correct 23 ms 110172 KB Output is correct
11 Correct 25 ms 110440 KB Output is correct
12 Correct 28 ms 110464 KB Output is correct
13 Correct 25 ms 110172 KB Output is correct
14 Correct 14 ms 110172 KB Output is correct
15 Correct 16 ms 110240 KB Output is correct
16 Correct 16 ms 110172 KB Output is correct
17 Correct 19 ms 110296 KB Output is correct
18 Correct 20 ms 110280 KB Output is correct
19 Correct 25 ms 110160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 110160 KB Output is correct
2 Correct 18 ms 110428 KB Output is correct
3 Correct 19 ms 110384 KB Output is correct
4 Correct 18 ms 110428 KB Output is correct
5 Correct 18 ms 110424 KB Output is correct
6 Correct 18 ms 110424 KB Output is correct
7 Correct 19 ms 110832 KB Output is correct
8 Correct 20 ms 110428 KB Output is correct
9 Correct 20 ms 110424 KB Output is correct
10 Correct 23 ms 110172 KB Output is correct
11 Correct 25 ms 110440 KB Output is correct
12 Correct 28 ms 110464 KB Output is correct
13 Correct 25 ms 110172 KB Output is correct
14 Correct 14 ms 110172 KB Output is correct
15 Correct 16 ms 110240 KB Output is correct
16 Correct 16 ms 110172 KB Output is correct
17 Correct 19 ms 110296 KB Output is correct
18 Correct 20 ms 110280 KB Output is correct
19 Correct 25 ms 110160 KB Output is correct
20 Correct 20 ms 110172 KB Output is correct
21 Correct 17 ms 110376 KB Output is correct
22 Incorrect 18 ms 110408 KB Output isn't correct
23 Halted 0 ms 0 KB -