답안 #499995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499995 2021-12-30T08:38:19 Z inksamurai Holding (COCI20_holding) C++17
0 / 110
0 ms 204 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>;

int main(){
_3qplfh5;
	int n,l,r,k;
	cin>>n>>l>>r>>k;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	assert(r==n);
	l--,r--;
	vi rbts;
	crep(i,l,r+1){
		rbts.pb(a[i]);
	}
	int m=r-l+1;
	vi psum=rbts;
	crep(i,1,m){
		psum[i]+=psum[i-1];
	}
	vec(vi) dp(m+1,vi(k+1,1e9)),nedp;
	rep(j,m+1) dp[j][0]=0;
	drep(i,l){
		nedp=dp;
		int x=a[i];
		rep(cost,k+1){
			vi pdp(m+1,1e9);
			pdp[m]=dp[m][cost];
			drep(j,m){
				pdp[j]=dp[j][cost];
				pdp[j]=min(pdp[j],pdp[j+1]);
			}
			drep(j,m){
				int necost=cost+j+l-i;
				if(necost<k){
					nedp[j][necost]=min(nedp[j][necost],pdp[j+1]+x-a[j+l]);
				}
			}
		}
		swap(dp,nedp);
	}
	int ans=1e9;
	rep(i,m+1){
		rep(j,k+1){
			if(dp[i][j]!=1e9){
				ans=min(ans,dp[i][j]+psum[m-1]);
			}
		}
	}
	cout<<ans<<"\n";
//
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -