답안 #920939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920939 2024-02-03T08:11:19 Z shoryu386 Kitchen (BOI19_kitchen) C++17
20 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin >> n >> m >> k;
	
	int buckets[n], balls[m];
	
	for (int x = 0; x < n; x++) cin >> buckets[x];
	for (int x = 0; x < m; x++) cin >> balls[x];
	
	#define IMP cout << "Impossible"; return 0;
	
	/*
	if (m == 1){
		//st1 pt 1
		if (k > 1){
			IMP;
		}
		
		int bucketsum = 0;
		for (int x = 0; x < n; x++){
			bucketsum += buckets[x];
		}
		
		if (bucketsum > balls[0]){
			IMP;
		}
		
		cout << balls[0] - bucketsum;
	}
	else if (m == 2){
		//st1 pt2
		if (k > 2){
			IMP;
		}
		else if (k == 2){
			
		}
		else{
			
		}
	}
	*/
	
	if (m <= 15){
		
		int ans = LLONG_MAX/20;
		for (int bm = 0; bm < (1LL<<m); bm++){
			vector<int> chefs;
			for (int x = 0; x < m; x++){
				if (bm & (1<<x)){
					chefs.push_back(balls[x]);
				}
			}
			
			sort(chefs.begin(), chefs.end());
			
			if (chefs.size() < k){
				continue;
			}
			
			priority_queue<int> chefsLeft;
			
			for (auto y : chefs) chefsLeft.push(y);
			
			for (int x = 0; x < (k-1)*n; x++){
				int cur = chefsLeft.top();
				cur--;
				
				chefsLeft.pop();
				chefsLeft.push(cur);
			}
			
			chefs.clear();
			
			bool dead = false;
			while (!chefsLeft.empty()){
				
				if (chefsLeft.top() < 0){
					dead = true;
					break;
				}
				
				chefs.push_back(chefsLeft.top());
				chefsLeft.pop();
			}
			
			for (int x = 0; x < n; x++){
				if (buckets[x] - k < 0){
					dead = true;
				}
			}
			
			if (dead){
				continue;
			}
			
			reverse(chefs.begin(), chefs.end()); //sorted again
			
			#define BSMAX 100000
			//300^2
			
			bitset<BSMAX> bs;
			bs[0] = 1;
			for (int x = 0; x < (int)(chefs.size()); x++){
				bs |= (bs << chefs[x]);
			}
			
			int bucketsum = 0;
			for (int x = 0; x < n; x++){
				
				bucketsum += (buckets[x] - (k-1));
			}
			
			int curans = -1;
			for (int x = bucketsum; x < BSMAX; x++){
				if (bs[x]){
					curans = x-bucketsum;
					break;
				}
			}
			
			if (curans != -1) ans = min(curans, ans);
			
		}
		
		if (ans == -1) {IMP;}
		else cout << ans;
	}
	else if (k == 1){
		//subtask 3
		#define BSMAX 100000
		//300^2
		
		bitset<BSMAX> bs;
		bs[0] = 1;
		
		for (int x = 0; x < m; x++){
			bs |= (bs << balls[x]);
		}
		
		int bucketsum = 0;
		for (int x = 0; x < n; x++){
			bucketsum += buckets[x];
		}
		
		int ans = -1;
		for (int x = bucketsum; x < BSMAX; x++){
			if (bs[x]){
				ans = x-bucketsum;
				break;
			}
		}
		
		if (ans == -1) cout << "Impossible";
		else cout << ans;
	}
}

Compilation message

kitchen.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
kitchen.cpp: In function 'int main()':
kitchen.cpp:63:21: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   63 |    if (chefs.size() < k){
      |        ~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -