Submission #973454

# Submission time Handle Problem Language Result Execution time Memory
973454 2024-05-02T02:40:20 Z modwwe Holding (COCI20_holding) C++17
110 / 110
89 ms 14208 KB
#include<bits/stdc++.h>
//#define int long long
#define d0 1
#define d1 11
#define d2 110
#define d3 1010
#define d4 10010
#define d5 100010
#define d6 1000010
#define down cout<<'\n';
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define debug(x) cerr<<x<<" ";
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define sz(s) s.size()
#define pii pair<int,int>
#define pb push_back
#define checktime   cout << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define reb(i,m,n) for(int i=m;i>=n;i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
void phongbeo();
void de();
template<typename A, typename B>istream& operator>>(istream& in, pair<A, B> &v) {
    in >> v.first >> v.second;
    return in;
}
template<typename A, typename B> ostream& operator<<(ostream& out, const pair<A, B> &v) {
    out << v.first << " " << v.second << " ";
    return out;
}
template < class T > bool minimize(T& a, const T& b) {
    return b < a ? a = b, 1 : 0;
}
template < class T > bool maximize(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count    ());
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy2[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int mod2=1e9+7;
const int mod=1073741824;
const int  mod1=998244353;
struct ib {
    int a;
    int b;
};
struct icd {
    int a,b;
};
struct ic {
    int a,b,c;
};
struct id {
    int a,b,c,d;
};
int minn=1e9,maxx=-1e9;
int n,m,s2,s4,s3,sf,k,l,r,dem=0,l1,r1,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0;
int  s,i;
int el=29;
main() {
#ifndef ONLINE_JUDGE
///fin(task),fou(task);
#endif
 NHP
//modwwe
    phongbeo(),down
#ifndef ONLINE_JUDGE
//checktime
#endif
}
int a[101],b[101],dp[102][10002][2],dp2[102][10002][2];
void phongbeo()
{
cin>>n>>l>>r>>k;
 for(int i=1;i<=n;i++)
    cin>>a[i],b[i]=b[i-1]+a[i];
 for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++){
 if(i>=l&&i<=r){dp[i][j][0]=1e8;dp[i][j][1]=b[i]-b[l-1];}
if(i<=r&&i>=l1)dp2[i][j][1]=b[r]-b[i-1],dp2[i][j][0]=1e8;
}
for(int j=1;j<=l-1;j++){
for(int i=l;i<=r;i++){
     for(int z=0;z<=k-i+j;z++)
    {
    dp[i][z+i-j][0]=min({dp[i][z+i-j][0],dp[i-1][z][1]+a[j],dp[i-1][z+i-j][0]+a[i]});
//dp[i][z][0]=min(dp[i-1][z][1]+a[i],dp[i][z][0]);
//cout<<dp[i][z+i-j][0]<<" "<<i<<" "<<j<<" "<<z<<" "<<z+i-j<<" "<<dp[i-1][z+i-j][0]<<" "<<dp[i-1][z][1]+a[j],down
    }
    for(int z=0;z<=k;z++){
        dp[i][z][0]=min({dp[i-1][z][0]+a[i],dp[i-1][z][1]+a[i],dp[i][z][0]});
        }

}
for(int i=l;i<=r;i++)
for(int z=0;z<=k;z++)
    dp[i][z][1]=min(dp[i][z][1],dp[i][z][0]),
    dp[i][z][0]=1e8;
   // for(int z=k+j-i+1;z<=k;z++)
      //  dp[i][z]=min(dp[i][z],dp[i-1][z]+a[i]);
    }
    for(int j=n;j>=r+1;j--){
for(int i=r;i>=l;--i){
    for(int z=0;z<=k-i+j;z++){
    dp2[i][z+j-i][0]=min({dp2[i][z+j-i][0],dp2[i+1][z][1]+a[j],dp2[i+1][z+j-i][0]+a[i]});
   //dp2[i][z]=min(dp2[i][z],dp2[i+1][z]+a[i]);
 }
   for(int z=0;z<=k;z++){
        dp2[i][z][0]=min({dp2[i+1][z][0]+a[i],dp2[i+1][z][1]+a[i],dp2[i][z][0]});
        }
 }
  for(int i=l;i<=r;i++)
 for(int z=0;z<=k;z++)
    dp2[i][z][1]=min(dp2[i][z][1],dp2[i][z][0]),
    dp2[i][z][0]=1e8;
 }

 for(int i=l;i<=r;i++)
    for(int z=1;z<=k;z++)
    dp[i][z][1]=min(dp[i][z][1],dp[i][z-1][1]),dp2[i][z][1]=min(dp2[i][z-1][1],dp2[i][z][1]);
dem=b[r]-b[l-1];

///cout<<"3131e1e1\n";
for(int i=l-1;i<=r;i++)
    for(int j=0;j<=k;j++){
    dem=min(dem,dp[i][j][1]+dp2[i+1][k-j][1]);
//cout<<dp[i][j][1]<<" "<<dp2[i+1][k-j][1]<<" "<<i<<" "<<j,down
    }
cout<<dem;
 }

Compilation message

holding.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 23 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 23 ms 8536 KB Output is correct
14 Correct 1 ms 6612 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 23 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 6616 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 23 ms 8536 KB Output is correct
14 Correct 1 ms 6612 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 23 ms 8540 KB Output is correct
20 Correct 3 ms 10584 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 4 ms 8796 KB Output is correct
24 Correct 4 ms 12892 KB Output is correct
25 Correct 89 ms 14208 KB Output is correct