Submission #385300

# Submission time Handle Problem Language Result Execution time Memory
385300 2021-04-04T03:49:23 Z rqi Kitchen (BOI19_kitchen) C++14
100 / 100
160 ms 3396 KB
#include <bits/stdc++.h>
using namespace std;

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

const int MOD = 1e9+7;

const int mx = 305;
int N, M, K;

int Asum = 0;
int A[mx];
int B[mx];
int Bp[mx];

bitset<305*305> dp1;
bitset<305*305> dp[305];

int main(){
	cin >> N >> M >> K;
	for(int i = 0; i < N; i++){
		cin >> A[i];
		Asum+=A[i];
	}
	for(int i = 0; i < M; i++){
		cin >> B[i];
	}

	for(int i = 0; i < N; i++){
		if(A[i] < K){
			cout << "Impossible" << "\n";
			exit(0);
		}
	}

	for(int i = 0; i < M; i++){
		Bp[i] = min(B[i], N);
	}

	// if(M <= 15){
	// 	int ans = MOD;
	// 	for(int i = 0; i < (1<<M); i++){
	// 		int Bsum = 0;
	// 		int Bpsum = 0;

	// 		for(int j = 0; j < M; j++){
	// 			if((i>>j)&1){
	// 				Bsum+=B[j];
	// 				Bpsum+=Bp[j];
	// 			}
	// 		}

	// 		if(Bsum >= Asum && Bpsum >= N*K){
	// 			ckmin(ans, Bsum);
	// 		}
	// 	}

	// 	if(ans == MOD){
	// 		cout << "Impossible" << "\n";
	// 	}
	// 	else{
	// 		cout << ans-Asum << "\n";
	// 	}
	// 	exit(0);
	// }
	
	dp1[0] = 1;
	for(int i = 0; i < M; i++){
		if(B[i] <= N){
			dp1|=(dp1<<B[i]);
		}
	}

	for(int i = 0; i < 305*305; i++){
		if(dp1[i] == 1){
			dp[min(i/N, K)][i] = 1;
		}
	}

	for(int i = 0; i < M; i++){
		if(B[i] <= N) continue;
		//cout << i << "\n";
		for(int j = K+1; j >= 1; j--){
			if(j == K+1){
				dp[K]|=(dp[K]<<B[i]);
			}
			else{
				dp[j]|=(dp[j-1]<<B[i]);
			}
			
		}

		// for(int j = 1; j <= K; j++){
		// 	for(int k = 0; k <= 12; k++){
		// 		cout << dp[j][k] << " ";
		// 	}
		// 	cout << "\n";
		// }
		// cout << "\n";
	}


	for(int i = Asum; i < 305*305; i++){
		if(dp[K][i] == 1){
			cout << i-Asum << "\n";
			exit(0);
		}
	}
	cout << "Impossible" << "\n";
	

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 3 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 748 KB Output is correct
2 Correct 3 ms 748 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 3 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 364 KB Output is correct
17 Correct 4 ms 364 KB Output is correct
18 Correct 3 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 126 ms 2668 KB Output is correct
26 Correct 110 ms 2688 KB Output is correct
27 Correct 51 ms 1900 KB Output is correct
28 Correct 53 ms 1900 KB Output is correct
29 Correct 160 ms 2668 KB Output is correct
30 Correct 123 ms 3396 KB Output is correct