답안 #921015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921015 2024-02-03T08:56:23 Z shoryu386 Kitchen (BOI19_kitchen) C++17
51 / 100
358 ms 492 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;
	
	bool dead = false;
	for (int x = 0; x < n; x++){
		if (buckets[x] < k){
			dead = true;
		}
	}
	if (dead) {IMP;}
	
	if (m <= 15){
		
		int ans = LLONG_MAX/20;
		
		int bucketSum = 0;
		for (int x = 0; x < n; x++) bucketSum += buckets[x]; 
		
		for (int bm = 0; bm < (1LL<<m); bm++){
			
			
			if (__builtin_popcountll(bm) < k){
				continue;
			}
			
			vector<int> chefs;
			
			for (int x = 0; x < m; x++){
				if (bm & (1<<x)){
					chefs.push_back(balls[x]);
				}
			}
			
			int chefsum = 0;
			for (int x = 0; x < chefs.size(); x++) chefsum += chefs[x];
			
			
			//can we support this?
			int needed[n]; for (int x = 0; x < n; x++) needed[x] = k;
		
			for (int x = 0; x < chefs.size(); x++){
				//for each chef, try and distribute
				for (int y = n-1; y > -1; y--){
					if (chefs[x] <= 0){
						break;
					}
					
					if (needed[y] > 0) needed[y]--, chefs[x]--;
				}
				sort(needed, needed+n);
			}
			
			bool works = true;
			for (int x = 0; x < n; x++){
				if (needed[x] != 0){
					works = false;
				}
			}
			
			for (int x = 0; x < chefs.size(); x++){
				//for each chef, try and distribute
				for (int y = 0; y < n; y++){
					if (chefs[x] <= 0){
						break;
					}
					
					if (needed[y] > 0) needed[y]--, chefs[x]--;
				}
			}
			
			if (works && chefsum >= bucketSum){
				ans = min(ans, chefsum - bucketSum);
			}
		}
		
		if (ans == LLONG_MAX/20) {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:49:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    for (int x = 0; x < chefs.size(); x++) chefsum += chefs[x];
      |                    ~~^~~~~~~~~~~~~~
kitchen.cpp:55:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    for (int x = 0; x < chefs.size(); x++){
      |                    ~~^~~~~~~~~~~~~~
kitchen.cpp:74:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    for (int x = 0; x < chefs.size(); x++){
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 34 ms 348 KB Output is correct
13 Correct 358 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 344 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 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 34 ms 348 KB Output is correct
13 Correct 358 ms 468 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 1 ms 348 KB Output isn't correct
21 Halted 0 ms 0 KB -