답안 #926126

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926126 2024-02-12T15:14:22 Z pragmatist Kitchen (BOI19_kitchen) C++17
100 / 100
50 ms 106488 KB
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<iomanip>
#include<bitset>

using namespace std;

const int N = (int)4e5 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7; 

int mult(int x, int y) {
	return 1ll*x*y%MOD;
}

int sum(int x, int y) {
	x += y;
	if(x >= MOD) {
		x -= MOD;
	}
	return x;
}

int sub(int x, int y) {
	x -= y;
	if(x < 0) {
		x += MOD;
	}
	return x;
}

int n, m, k;
int a[301], b[301], dp[301][90001];

int main() {	
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cin >> n >> m >> k;
	int tot = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		tot += a[i];
	}
	for(int i = 1; i <= m; ++i) {
		cin >> b[i];
	}
	if(m<k) {
		cout << "Impossible\n";
		return 0;
	}
	for(int i = 1; i <= n; ++i) {
		if(a[i] < k) {
			cout << "Impossible\n";
			return 0;
		}
	}
	for(int i = 0; i <= m; ++i) {
		for(int w = 0; w <= 9e4; ++w) {
			dp[i][w] = -inf;
		}
	}
	dp[0][0] = 0;
	for(int i = 1; i <= m; ++i) {
		int x = min(n, b[i]);
		for(int w = 0; w <= 9e4; ++w) {
			dp[i][w] = dp[i-1][w];
			if(w>=b[i]) {
				dp[i][w] = max(dp[i][w], dp[i-1][w-b[i]]+x);
			}
		}
	}
	int ans = inf;
	for(int w = tot; w <= 9e4; ++w) {
		if(dp[m][w] >= n*k) {
			cout << w-tot << "\n";
			return 0;
		}
	}
	cout << "Impossible\n";
	return 0;
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:81:6: warning: unused variable 'ans' [-Wunused-variable]
   81 |  int ans = inf;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 3 ms 6744 KB Output is correct
10 Correct 3 ms 6744 KB Output is correct
11 Correct 3 ms 6744 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 92764 KB Output is correct
2 Correct 37 ms 80476 KB Output is correct
3 Correct 50 ms 106332 KB Output is correct
4 Correct 49 ms 106488 KB Output is correct
5 Correct 49 ms 103004 KB Output is correct
6 Correct 35 ms 74488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14940 KB Output is correct
2 Correct 8 ms 15004 KB Output is correct
3 Correct 7 ms 14940 KB Output is correct
4 Correct 7 ms 14936 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 3 ms 6744 KB Output is correct
10 Correct 3 ms 6744 KB Output is correct
11 Correct 3 ms 6744 KB Output is correct
12 Correct 3 ms 6748 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 47 ms 92764 KB Output is correct
15 Correct 37 ms 80476 KB Output is correct
16 Correct 50 ms 106332 KB Output is correct
17 Correct 49 ms 106488 KB Output is correct
18 Correct 49 ms 103004 KB Output is correct
19 Correct 35 ms 74488 KB Output is correct
20 Correct 7 ms 14940 KB Output is correct
21 Correct 8 ms 15004 KB Output is correct
22 Correct 7 ms 14940 KB Output is correct
23 Correct 7 ms 14936 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 39 ms 76380 KB Output is correct
26 Correct 42 ms 86616 KB Output is correct
27 Correct 27 ms 57944 KB Output is correct
28 Correct 41 ms 86620 KB Output is correct
29 Correct 44 ms 88920 KB Output is correct
30 Correct 50 ms 106308 KB Output is correct