Submission #500141

# Submission time Handle Problem Language Result Execution time Memory
500141 2021-12-30T11:26:56 Z inksamurai Holding (COCI20_holding) C++17
110 / 110
260 ms 8296 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3qplfh5 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;

const int inf=1e9;

int main(){
_3qplfh5;
	int n,l,r,k;
	cin>>n>>l>>r>>k;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	l--,r--;
	int m=r-l+1;
	vec(vi) dp(m,vi(k+1,inf)),nedp;
	{
		rep(j,m){
			dp[j][0]=0;
		}
		rep(i,l){
			nedp=dp;
			rep(cost,k+1){
				vi pdp(m,inf);
				pdp[0]=dp[0][cost];
				crep(j,1,m){
					pdp[j]=dp[j][cost];
					pdp[j]=min(pdp[j],pdp[j-1]);
				}
				rep(j,m){
					int necost=cost+j+l-i;
					if(necost>k) continue;
					nedp[j][necost]=min(nedp[j][necost],(j==0?0:pdp[j-1])+a[i]-a[j+l]);
				}
			}
			swap(dp,nedp);
		}
	}
	vec(vi) fdp=dp;
	{
		rep(j,k+1){
			rep(i,m){
				if(i) fdp[i][j]=min(fdp[i][j],fdp[i-1][j]);
				if(j) fdp[i][j]=min(fdp[i][j],fdp[i][j-1]);
			}
		}
	}
	dp=vec(vi)(m,vi(k+1,inf));
	{
		rep(j,m){
			dp[j][0]=0;
		}
		drep(i,n){
			if(i==r) break;
			nedp=dp;
			rep(cost,k+1){
				vi pdp(m,inf);
				pdp[m-1]=dp[m-1][cost];
				drep(j,m-1){
					pdp[j]=dp[j][cost];
					pdp[j]=min(pdp[j],pdp[j+1]);
				}
				rep(j,m){
					int necost=cost+i-(j+l);
					if(necost>k) continue;
					nedp[j][necost]=min(nedp[j][necost],(j+1>=m?0:pdp[j+1])+a[i]-a[j+l]);
				}
			}
			swap(dp,nedp);
		}
	}
	int ans=fdp[m-1][k];
	rep(j,m){
		rep(cost,k+1){
			ans=min(ans,dp[j][cost]+(j==0?0:fdp[j-1][k-cost]));
		}
	}
	crep(i,l,r+1){
		ans+=a[i];
	}
	cout<<ans<<"\n";
//	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 4 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 4 ms 1356 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 52 ms 4412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 4 ms 1356 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 52 ms 4412 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 51 ms 4420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 4 ms 1356 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 52 ms 4412 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 51 ms 4420 KB Output is correct
20 Correct 4 ms 312 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 11 ms 456 KB Output is correct
24 Correct 7 ms 588 KB Output is correct
25 Correct 260 ms 8296 KB Output is correct