답안 #750708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750708 2023-05-30T07:52:12 Z bgnbvnbv Holding (COCI20_holding) C++14
110 / 110
24 ms 26996 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=int;
const ll maxN=103;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,l,r,k;
ll a[maxN],dp[maxN][maxN][maxN*maxN/4],sum=0;
void solve()
{
    cin >> n >> l >> r >> k;
    k=min(k,n*n/4+1);
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=l;i<=r;i++) sum+=a[i];
    // dpr
    for(int i=r+1;i<=n;i++)
    {
        for(int j=r;j>=l;j--)
        {
            for(int q=0;q<=k;q++)
            {
                dp[i][j][q]=max({dp[i-1][j][q],dp[i][j+1][q]});
                if(q-(i-j)>=0) dp[i][j][q]=max(dp[i][j][q],dp[i-1][j+1][q-(i-j)]+a[j]-a[i]);
            }
        }
    }
    for(int i=l-1;i>=1;i--)
    {
        for(int j=l;j<=r;j++)
        {
            for(int q=0;q<=k;q++)
            {
                dp[i][j][q]=max({dp[i+1][j][q],dp[i][j-1][q]});
                if(q-(j-i)>=0) dp[i][j][q]=max(dp[i][j][q],dp[i+1][j-1][q-(j-i)]+a[j]-a[i]);
            }
        }
    }
    ll ans=sum;
    for(int i=l-1;i<=r;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if(j-1>=0) dp[1][i][j]=max(dp[1][i][j],dp[1][i][j-1]);
        }
    }
    for(int i=l;i<=r+1;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if(j-1>=0) dp[n][i][j]=max(dp[n][i][j],dp[n][i][j-1]);
        }
    }
    for(int i=l;i<=r+1;i++)
    {
        for(int ss=0;ss<=k;ss++) ans=min(ans,sum-dp[1][i-1][ss]-dp[n][i][k-ss]);
    }
    cout << ans;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

holding.cpp:11:14: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
   11 | const ll inf=1e18;
      |              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 2496 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 2 ms 3284 KB Output is correct
12 Correct 1 ms 2132 KB Output is correct
13 Correct 3 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 2496 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 2 ms 3284 KB Output is correct
12 Correct 1 ms 2132 KB Output is correct
13 Correct 3 ms 4564 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 4 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 2 ms 2496 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 2 ms 3284 KB Output is correct
12 Correct 1 ms 2132 KB Output is correct
13 Correct 3 ms 4564 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 1236 KB Output is correct
16 Correct 2 ms 1620 KB Output is correct
17 Correct 2 ms 1748 KB Output is correct
18 Correct 2 ms 2900 KB Output is correct
19 Correct 4 ms 4564 KB Output is correct
20 Correct 4 ms 6356 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 4564 KB Output is correct
23 Correct 3 ms 2900 KB Output is correct
24 Correct 6 ms 11988 KB Output is correct
25 Correct 24 ms 26996 KB Output is correct