답안 #231845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231845 2020-05-15T04:54:20 Z kshitij_sodani Kitchen (BOI19_kitchen) C++17
100 / 100
67 ms 1024 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
int n,m,k;
int aa[301];
int bb[301];
const int li=400*400;
int dp[li];
int su=0;
int ans2=-1;
int brute(int ind,int su2=0,int su3=0){
	if(ind==m){
		if(su2>=k*n and su3>=su){
			if(ans2==-1){
				ans2=su3-su;
			}
			else{
				ans2=min(ans2,su3-su);
			}
		}
	}
	else{
		brute(ind+1,su2,su3);
		brute(ind+1,su2+min(bb[ind],n),su3+bb[ind]);
	}

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	cin>>n>>m>>k;
	int st=0;
	for(int i=0;i<n;i++){
		cin>>aa[i];
		su+=aa[i];
		if(aa[i]<k){
			st=1;
		}
	}
	
	int tt=0;
	for(int i=0;i<m;i++){
		cin>>bb[i];
		tt+=bb[i];
	}
	if(st){
		cout<<"Impossible"<<endl;
		return 0;
	}
	if(tt<su){
		cout<<"Impossible"<<endl;
		return 0;
	}
	for(int i=0;i<m;i++){
		for(int j=li-1;j>=bb[i];j--){
			if(dp[j-bb[i]]>-1){
				dp[j]=max(dp[j],dp[j-bb[i]]+min(bb[i],n));
			}
		}
	}
	int ans5=-1;
	for(int i=su;i<li;i++){
		if(dp[i]>=k*n){
			if(ans5==-1){
				ans5=i-su;;
			}
			else{
				ans5=min(ans5,i-su);
			}
		}
	}
	if(ans5==-1){
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<ans5<<endl;


/*	if(k==1){
		for(int i=0;i<m;i++){
			for(int j=li;j>=bb[i];j--){
				dp[j]=max(dp[j],dp[j-bb[i]]);
			}
		}
		int ans=-1;
		for(int i=su;i<li;i++){
			if(dp[i]){
				ans=i-su;
				break;
			}
		}
		if(ans==-1){
			cout<<"Impossible"<<endl;
		}
		else{
			cout<<ans<<endl;
		}
	}
	else if(m<=15){
		brute(0);
		if(ans2==-1){
			cout<<"Impossible"<<endl;
		}
		else{
			cout<<ans2<<endl;
		}
	}
	else{

	}*/














	return 0;
}

Compilation message

kitchen.cpp: In function 'int brute(int, int, int)':
kitchen.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 7 ms 896 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 7 ms 896 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 11 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 8 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 896 KB Output is correct
2 Correct 52 ms 1016 KB Output is correct
3 Correct 65 ms 896 KB Output is correct
4 Correct 67 ms 1004 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 47 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 896 KB Output is correct
2 Correct 13 ms 896 KB Output is correct
3 Correct 13 ms 896 KB Output is correct
4 Correct 13 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 896 KB Output is correct
3 Correct 7 ms 896 KB Output is correct
4 Correct 7 ms 896 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 896 KB Output is correct
9 Correct 11 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 8 ms 896 KB Output is correct
13 Correct 8 ms 896 KB Output is correct
14 Correct 57 ms 896 KB Output is correct
15 Correct 52 ms 1016 KB Output is correct
16 Correct 65 ms 896 KB Output is correct
17 Correct 67 ms 1004 KB Output is correct
18 Correct 5 ms 896 KB Output is correct
19 Correct 47 ms 896 KB Output is correct
20 Correct 13 ms 896 KB Output is correct
21 Correct 13 ms 896 KB Output is correct
22 Correct 13 ms 896 KB Output is correct
23 Correct 13 ms 1024 KB Output is correct
24 Correct 5 ms 1024 KB Output is correct
25 Correct 48 ms 896 KB Output is correct
26 Correct 58 ms 1024 KB Output is correct
27 Correct 39 ms 1024 KB Output is correct
28 Correct 51 ms 896 KB Output is correct
29 Correct 52 ms 1024 KB Output is correct
30 Correct 63 ms 1020 KB Output is correct