Submission #392192

# Submission time Handle Problem Language Result Execution time Memory
392192 2021-04-20T15:47:15 Z Blistering_Barnacles Holding (COCI20_holding) C++11
110 / 110
131 ms 113244 KB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef int ll;
ll n,l,r,k,a[109];
ll dp1[109][109][10009];
ll dp2[109][109][10009];
ll best2(ll i,ll j,ll op)
{
    if(op < 0)return 1e9 ;
    if(j==n+2)
        return 1e9;
    if(i==r+1)
        return 0;
    ll &ret=dp2[i-l+1][j-r+1][op];
    //cout<<2<<"  "<<i<<" "<<j<<" "<<op<<endl;
    if(ret!=-1)
        return ret;
    ret=best2(i,j+1,op);
    ret=min(ret,best2(i+1,j,op)+a[i]);
    ret=min(ret,best2(i+1,j+1,op-j+i)+a[j]);
    return ret;
}
ll best1(ll i,ll j,ll op)
{
    //cout<<1<<" "<<i<<" "<<j<<" "<<op<<endl;
    if(op < 0)return 1e9 ;
    if(j==r+2)
        return 1e9;
    if(i==l)
        return best2(j,r+1,op);
    ll &ret=dp1[i][j-l+1][op];
   // cout << ret << endl ;
    if(ret!=-1)
        return ret;
    ret=best1(i+1,j,op);
    ret=min(ret,best1(i,j+1,op)+a[j]);
    ret=min(ret,best1(i+1,j+1,op-j+i)+a[i]);
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>l>>r>>k;
    for(ll i=1; i<=n; i++)
        cin>>a[i];
    for(ll i=0; i<=l; i++)
        for(ll j=0; j<=r-l+2; j++)
            for(ll op=0; op<=k; op++)
                dp1[i][j][op]=-1;

    for(ll i=0; i<=r-l+2; i++)
        for(ll j=0; j<=n-r+2; j++)
            for(ll op=0; op<=k; op++)
                dp2[i][j][op]=-1;
    cout<<best1(1,l,k);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 3 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 3 ms 3916 KB Output is correct
8 Correct 3 ms 3404 KB Output is correct
9 Correct 3 ms 3532 KB Output is correct
10 Correct 4 ms 4044 KB Output is correct
11 Correct 5 ms 4300 KB Output is correct
12 Correct 3 ms 3148 KB Output is correct
13 Correct 24 ms 32480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 3 ms 3916 KB Output is correct
8 Correct 3 ms 3404 KB Output is correct
9 Correct 3 ms 3532 KB Output is correct
10 Correct 4 ms 4044 KB Output is correct
11 Correct 5 ms 4300 KB Output is correct
12 Correct 3 ms 3148 KB Output is correct
13 Correct 24 ms 32480 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1740 KB Output is correct
16 Correct 2 ms 2248 KB Output is correct
17 Correct 2 ms 2380 KB Output is correct
18 Correct 4 ms 3660 KB Output is correct
19 Correct 22 ms 32460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 716 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 3 ms 3916 KB Output is correct
8 Correct 3 ms 3404 KB Output is correct
9 Correct 3 ms 3532 KB Output is correct
10 Correct 4 ms 4044 KB Output is correct
11 Correct 5 ms 4300 KB Output is correct
12 Correct 3 ms 3148 KB Output is correct
13 Correct 24 ms 32480 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 1740 KB Output is correct
16 Correct 2 ms 2248 KB Output is correct
17 Correct 2 ms 2380 KB Output is correct
18 Correct 4 ms 3660 KB Output is correct
19 Correct 22 ms 32460 KB Output is correct
20 Correct 12 ms 8048 KB Output is correct
21 Correct 4 ms 4556 KB Output is correct
22 Correct 4 ms 5452 KB Output is correct
23 Correct 5 ms 8396 KB Output is correct
24 Correct 24 ms 14668 KB Output is correct
25 Correct 131 ms 113244 KB Output is correct