답안 #745838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745838 2023-05-21T08:37:36 Z vjudge1 Kitchen (BOI19_kitchen) C++17
20 / 100
85 ms 3644 KB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct meal {
	int t, k;
	bool operator<(const  meal& m)const {
		return k < m.k;
	}
};

int check(int mask, vector<int>& ch, vector<meal>& m) {
	priority_queue<meal> q;
	int sum = 0;
	for (meal i : m) {
		q.push(i);
		sum += i.t;
	}
	for (int i = 0; i < ch.size(); i++) {
		if (((1 << i)&mask) == 0)continue;
		sum -= ch[i];
		vector<meal> out;
		for (int j = 0; j < ch[i]; j++) {
			if (q.empty())break;
			meal x = q.top();
			q.pop();
			x.k--;
			out.push_back(x);
		}
		for (meal j : out)q.push(j);
	}
	if (q.top().k > 0 || sum > 0)return INT32_MAX;
	return -sum;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m, k;
	cin >> n >> m >> k;
	vector<meal> meals(n);
	bool b = 1;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> meals[i].t;
		meals[i].k = k;
		if (meals[i].t < k)b = 0;
		sum += meals[i].t;
	}

	vector<int> ch(m);
	for (int& i : ch)cin >> i;
	
/*	for (int i = 0; i < (1 << m); i++) {
		ans = min(ans, check(i, ch, meals));
	}*/
	vector<vector<bool>> dp(m+1, vector<bool>(300*300, 0));
	dp[0][0] = 1;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j <= 90000; j++) {
			if (dp[i][j]) {
				dp[i + 1][j] = 1;
				dp[i + 1][j + ch[i]] = 1;
			}
		}
	}
	if (b) {
		for (int i = sum; i <= 90000; i++) {
			if (dp[m][i]) {
				cout << i - sum << '\n';
				return 0;
			}
		}
	}
	cout << "Impossible\n";
}

Compilation message

kitchen.cpp: In function 'int check(int, std::vector<int>&, std::vector<meal>&)':
kitchen.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int i = 0; i < ch.size(); i++) {
      |                  ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3156 KB Output is correct
2 Correct 27 ms 2772 KB Output is correct
3 Correct 60 ms 3644 KB Output is correct
4 Correct 85 ms 3644 KB Output is correct
5 Correct 78 ms 3540 KB Output is correct
6 Correct 24 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -