답안 #209613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209613 2020-03-14T21:22:28 Z papa Holding (COCI20_holding) C++14
110 / 110
83 ms 108920 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 100+5;
const int maxk = 10000/4+5;
int n,k;
int l,r;
int a[maxn];
int s;
int sol;
int dp[maxn][maxn][maxk];
int sl[maxn][maxk];

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    
    cin >> n >> l >> r >> k;
    
    k = min(k,n*n/4+2);
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=l;i<=r;i++) s+=a[i];
    for(int i=l;i<=r;i++)
    {
        for(int j=l-1;j>0;j--)
        {
            for(int kk=0;kk<=k;kk++)
            {
                dp[i][j][kk] = max(dp[i][j][kk],dp[i-1][j][kk]);
                dp[i][j][kk] = max(dp[i][j][kk],dp[i][j+1][kk]);
                int cena = i-j;
                if(kk>=cena) dp[i][j][kk] = max(dp[i][j][kk],dp[i-1][j+1][kk-cena] + a[i]-a[j]);
            }
        }
    }
    
    for(int i=l-1;i<=r;i++)
       for(int j=0;j<=k;j++)
         sl[i][j] = dp[i][1][j];
         
    
    memset(dp,0,sizeof dp);
    
    for(int i=r;i>=l;i--)
    {
        for(int j=r+1;j<=n;j++)
        {
            for(int kk=0;kk<=k;kk++)
            {
                dp[i][j][kk] = max(dp[i][j][kk],dp[i+1][j][kk]);
                dp[i][j][kk] = max(dp[i][j][kk],dp[i][j-1][kk]);
                int cena = j-i;
                if(kk >= cena) dp[i][j][kk] = max(dp[i][j][kk],dp[i+1][j-1][kk-cena] + a[i] - a[j]);
            }
        }
    }
    
    for(int i=l-1;i<=r;i++)
       for(int j=0;j<=k;j++)
         sol = max(sol,sl[i][j] + dp[i+1][n][k-j]);
    
    cout << s-sol;
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 108408 KB Output is correct
2 Correct 62 ms 108280 KB Output is correct
3 Correct 59 ms 108536 KB Output is correct
4 Correct 59 ms 108536 KB Output is correct
5 Correct 59 ms 108460 KB Output is correct
6 Correct 59 ms 108536 KB Output is correct
7 Correct 61 ms 108280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 108408 KB Output is correct
2 Correct 62 ms 108280 KB Output is correct
3 Correct 59 ms 108536 KB Output is correct
4 Correct 59 ms 108536 KB Output is correct
5 Correct 59 ms 108460 KB Output is correct
6 Correct 59 ms 108536 KB Output is correct
7 Correct 61 ms 108280 KB Output is correct
8 Correct 59 ms 108536 KB Output is correct
9 Correct 61 ms 108536 KB Output is correct
10 Correct 59 ms 108536 KB Output is correct
11 Correct 60 ms 108536 KB Output is correct
12 Correct 61 ms 108664 KB Output is correct
13 Correct 62 ms 108664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 108408 KB Output is correct
2 Correct 62 ms 108280 KB Output is correct
3 Correct 59 ms 108536 KB Output is correct
4 Correct 59 ms 108536 KB Output is correct
5 Correct 59 ms 108460 KB Output is correct
6 Correct 59 ms 108536 KB Output is correct
7 Correct 61 ms 108280 KB Output is correct
8 Correct 59 ms 108536 KB Output is correct
9 Correct 61 ms 108536 KB Output is correct
10 Correct 59 ms 108536 KB Output is correct
11 Correct 60 ms 108536 KB Output is correct
12 Correct 61 ms 108664 KB Output is correct
13 Correct 62 ms 108664 KB Output is correct
14 Correct 58 ms 108408 KB Output is correct
15 Correct 60 ms 108408 KB Output is correct
16 Correct 60 ms 108408 KB Output is correct
17 Correct 61 ms 108512 KB Output is correct
18 Correct 60 ms 108536 KB Output is correct
19 Correct 62 ms 108536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 108408 KB Output is correct
2 Correct 62 ms 108280 KB Output is correct
3 Correct 59 ms 108536 KB Output is correct
4 Correct 59 ms 108536 KB Output is correct
5 Correct 59 ms 108460 KB Output is correct
6 Correct 59 ms 108536 KB Output is correct
7 Correct 61 ms 108280 KB Output is correct
8 Correct 59 ms 108536 KB Output is correct
9 Correct 61 ms 108536 KB Output is correct
10 Correct 59 ms 108536 KB Output is correct
11 Correct 60 ms 108536 KB Output is correct
12 Correct 61 ms 108664 KB Output is correct
13 Correct 62 ms 108664 KB Output is correct
14 Correct 58 ms 108408 KB Output is correct
15 Correct 60 ms 108408 KB Output is correct
16 Correct 60 ms 108408 KB Output is correct
17 Correct 61 ms 108512 KB Output is correct
18 Correct 60 ms 108536 KB Output is correct
19 Correct 62 ms 108536 KB Output is correct
20 Correct 61 ms 108452 KB Output is correct
21 Correct 61 ms 108536 KB Output is correct
22 Correct 60 ms 108412 KB Output is correct
23 Correct 62 ms 108408 KB Output is correct
24 Correct 63 ms 108792 KB Output is correct
25 Correct 83 ms 108920 KB Output is correct