답안 #401347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401347 2021-05-09T22:41:47 Z idontreallyknow Kitchen (BOI19_kitchen) C++17
100 / 100
356 ms 115360 KB
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}
const int mx = 305, inf = 1e9+5;
int a[mx], b[mx], good[mx*mx], mi[mx][mx*mx], tot;
bitset<mx*mx> bs[mx];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,k;
	cin >> n >> m >> k;
	bool ok = true;
	for (int q = 1; q <= n; q++) {
		cin >> a[q];
		tot += a[q];
		if (a[q] < k) ok = false;
	}
	vector<int> small, large;
	for (int q = 1; q <= m; q++) {
		cin >> b[q];
		if (b[q] < n) small.push_back(b[q]);
		else large.push_back(b[q]);
	}
	if (!ok) {
		cout << "Impossible\n";
		return 0;
	}
	good[0] = 1;
	for (int q : small) {
		for (int w = mx*mx-1; w >= 0; w--) if (w-q >= 0) good[w] |= good[w-q];
	}
	bs[0][0] = 1;
	for (int q : large) {
		for (int w = mx-1; w >= 1; w--) {
			bs[w] |= (bs[w-1]<<q);
		}
	}
	for (int q = mx-1; q >= 0; q--) {
		for (int w = mx*mx-1; w >= 0; w--) {
			mi[q][w] = inf;
			if (bs[q][w]) mi[q][w] = w;
			if (q < mx-1) chkmin(mi[q][w], mi[q+1][w]);
			if (w < mx*mx-1) chkmin(mi[q][w], mi[q][w+1]);
		}
	}
	int ans = inf;
	for (int q = 0; q < mx*mx; q++) {
		if (!good[q]) continue;
		int f = (q >= n*k ? 0 : (n*k-q+n-1)/n), g = max(0,tot-q);
		chkmin(ans, mi[f][g]+q);
	}
	if (ans == inf) cout << "Impossible\n";
	else cout << ans-tot << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 114784 KB Output is correct
2 Correct 110 ms 114824 KB Output is correct
3 Correct 108 ms 114808 KB Output is correct
4 Correct 109 ms 114836 KB Output is correct
5 Correct 106 ms 111736 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 107 ms 114824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 114784 KB Output is correct
2 Correct 110 ms 114824 KB Output is correct
3 Correct 108 ms 114808 KB Output is correct
4 Correct 109 ms 114836 KB Output is correct
5 Correct 106 ms 111736 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 107 ms 114824 KB Output is correct
9 Correct 122 ms 114784 KB Output is correct
10 Correct 123 ms 114784 KB Output is correct
11 Correct 123 ms 115360 KB Output is correct
12 Correct 106 ms 111696 KB Output is correct
13 Correct 106 ms 111636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 111684 KB Output is correct
2 Correct 154 ms 111752 KB Output is correct
3 Correct 142 ms 115176 KB Output is correct
4 Correct 233 ms 115092 KB Output is correct
5 Correct 177 ms 115148 KB Output is correct
6 Correct 129 ms 111680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 115152 KB Output is correct
2 Correct 133 ms 115076 KB Output is correct
3 Correct 119 ms 115180 KB Output is correct
4 Correct 117 ms 115144 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 114784 KB Output is correct
2 Correct 110 ms 114824 KB Output is correct
3 Correct 108 ms 114808 KB Output is correct
4 Correct 109 ms 114836 KB Output is correct
5 Correct 106 ms 111736 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 107 ms 114824 KB Output is correct
9 Correct 122 ms 114784 KB Output is correct
10 Correct 123 ms 114784 KB Output is correct
11 Correct 123 ms 115360 KB Output is correct
12 Correct 106 ms 111696 KB Output is correct
13 Correct 106 ms 111636 KB Output is correct
14 Correct 134 ms 111684 KB Output is correct
15 Correct 154 ms 111752 KB Output is correct
16 Correct 142 ms 115176 KB Output is correct
17 Correct 233 ms 115092 KB Output is correct
18 Correct 177 ms 115148 KB Output is correct
19 Correct 129 ms 111680 KB Output is correct
20 Correct 147 ms 115152 KB Output is correct
21 Correct 133 ms 115076 KB Output is correct
22 Correct 119 ms 115180 KB Output is correct
23 Correct 117 ms 115144 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 356 ms 115132 KB Output is correct
26 Correct 337 ms 115132 KB Output is correct
27 Correct 250 ms 115132 KB Output is correct
28 Correct 254 ms 115172 KB Output is correct
29 Correct 352 ms 114736 KB Output is correct
30 Correct 271 ms 115116 KB Output is correct