답안 #862301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862301 2023-10-18T03:16:57 Z maks007 Kitchen (BOI19_kitchen) C++14
0 / 100
1 ms 348 KB
// Bismi Allah
#include "bits/stdc++.h"

using namespace std;

#define int long long

signed main () {
	int n, m, k;
	cin >> n >> m >> k;
	int meal[n], chef[m], mealCopy[n];
	for(int i = 0; i < n; i ++) cin >> meal[i];
	for(int i = 0; i < n; i ++) {
		if(meal[i] < k) {
			cout << "Impossible";
			return 0;
		}
	}
	if(m < k) {
		cout << "Impossible\n";
		return 0;
	}
	for(int i = 0; i < m; i ++) cin >> chef[i];
	if(m == 2) {
		if(accumulate(meal, meal + n, 0LL) <= chef[0] + chef[1] && min(chef[0], chef[1]) >= n) {
			cout << chef[0] + chef[1] - accumulate(meal, meal + n, 0LL);
		}else cout << "Impossible";
		return 0;
	}
	assert(false);
	for(int i = 0; i < n; i ++) mealCopy[i] = meal[i];
	int ans = 1e9;
	for(int mask = 0; mask < (1 << m); mask ++) {
		if(__builtin_popcount(mask) < k) continue;
		vector <int> cook;
		for(int i = 0; i < m; i ++) {
			if(mask & (1 << i)) cook.push_back(chef[i]-1);
		}
		for(int i = 0; i < n; i ++) meal[i] -= k;
		int res = 0, cur = 0;
		for(int i = 0; i < n; i ++) {
			if(meal[i] == 0) continue;
			if(cur == cook.size()) {
				cout << "Impossible\n";
				goto end;
			}
			if(cook[cur] > meal[i]) {
				cook[cur] -= meal[i];
				meal[i] = 0;
			}else {
				meal[i] -= cook[cur];
				cook[cur]=0;
				cur ++, i --;
			}
		}
		res = accumulate(cook.begin(), cook.end(), 0LL);
		ans = min(ans, res);
		end:;
		for(int i = 0; i < n; i ++) meal[i] = mealCopy[i];
	}
	if(ans == 1e9) cout << "Impossible";
	else cout << ans;
	return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:43:11: 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]
   43 |    if(cur == cook.size()) {
      |       ~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -