답안 #657033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657033 2022-11-08T19:09:23 Z inksamurai Kitchen (BOI19_kitchen) C++17
0 / 100
5 ms 596 KB
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3NRqilq ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

void chmin(int&a,int b){
	a=min(a,b);
}

signed main(){
_3NRqilq;	
	int n,m,k;
	cin>>n>>m>>k;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	vi b(m);
	rep(i,m){
		cin>>b[i];
	}
	const int _n=500;
	const int inf=1e9;
	vec(vi) dp(_n+1,vi(k+1,inf)),ndp;
	// minimum additional, k
	dp[0][0]=0;
	rep(i,m){
		int v=b[i];
		ndp=dp;
		for(int j=0;j<_n;j++){
			rep(e,k){
				int nj=j+v;
				int ne=e+1;
				if(j+v<=_n){
					chmin(ndp[nj][ne],dp[j][e]);
				}else{
					chmin(ndp[_n][ne],dp[j][e]+nj-_n);
				}
			}
		}
		rep(e,k+1){
			for(int j=_n-1;j>=e;j--){
				chmin(ndp[j][e],ndp[j+1][e]+1);
				// if(e==2){
				// 	print(ndp[j][e]);
				// }
			}
		}
		dp.swap(ndp);
	}
	// print(dp[5][2]);
	int ans=0;
	rep(i,n){
		ans+=dp[a[i]][k];
	}
	if(ans>=inf){
		cout<<"impossible\n";
	}else{
		cout<<ans<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -