답안 #584244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584244 2022-06-27T05:19:09 Z amunduzbaev Kitchen (BOI19_kitchen) C++17
100 / 100
198 ms 114160 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int ll

const int N = 305;
int a[N], b[N];
bitset<N * N> tp[N], dp;
int dd[N][N * N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, k; cin>>n>>m>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i] < k){
			cout<<"Impossible\n";
			return 0;
		}
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	
	int sum = accumulate(a, a + n, 0);
	sort(b, b + m);
	int l = m, tot = 0;
	dp[0] = 1;
	for(int i=0;i<m;i++){
		if(b[i] > n) { l = i; break; }
		tot += b[i];
		dp |= (dp << b[i]);
	}
	
	tp[0][0] = 1;
	for(int i=l;i<m;i++){
		int v = b[i];
		for(int j=i-l+1;j>0;j--){
			tp[j] |= (tp[j - 1] << v);
		}
	}
	
	for(int j=0;j<N;j++){
		dd[j][N * N - 1] = 1e9;
		for(int k=N * N - 2;~k;k--){
			if(tp[j][k]) dd[j][k] = 0;
			else dd[j][k] = dd[j][k + 1] + 1;
		}
	}
	
	int res = 1e9, c = 0;
	while(c <= m - l){
		for(int j=k * n;j<=tot;j++){
			if(dp[j]){
				res = min(res, dd[c][max(0, sum - j)] + max(0, j - sum));
			}
		}
		
		c++;
		if(k) k--;
	}
	
	if(res == 1e9) cout<<"Impossible\n";
	else cout<<res<<"\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 111308 KB Output is correct
2 Correct 121 ms 111392 KB Output is correct
3 Correct 126 ms 111288 KB Output is correct
4 Correct 114 ms 111328 KB Output is correct
5 Correct 113 ms 111404 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 119 ms 111308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 111308 KB Output is correct
2 Correct 121 ms 111392 KB Output is correct
3 Correct 126 ms 111288 KB Output is correct
4 Correct 114 ms 111328 KB Output is correct
5 Correct 113 ms 111404 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 119 ms 111308 KB Output is correct
9 Correct 115 ms 111532 KB Output is correct
10 Correct 115 ms 111512 KB Output is correct
11 Correct 116 ms 111436 KB Output is correct
12 Correct 122 ms 111356 KB Output is correct
13 Correct 130 ms 111268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 111344 KB Output is correct
2 Correct 114 ms 111384 KB Output is correct
3 Correct 116 ms 111380 KB Output is correct
4 Correct 143 ms 112596 KB Output is correct
5 Correct 125 ms 111352 KB Output is correct
6 Correct 115 ms 111372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 111676 KB Output is correct
2 Correct 115 ms 111604 KB Output is correct
3 Correct 124 ms 111372 KB Output is correct
4 Correct 118 ms 111384 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 111308 KB Output is correct
2 Correct 121 ms 111392 KB Output is correct
3 Correct 126 ms 111288 KB Output is correct
4 Correct 114 ms 111328 KB Output is correct
5 Correct 113 ms 111404 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 119 ms 111308 KB Output is correct
9 Correct 115 ms 111532 KB Output is correct
10 Correct 115 ms 111512 KB Output is correct
11 Correct 116 ms 111436 KB Output is correct
12 Correct 122 ms 111356 KB Output is correct
13 Correct 130 ms 111268 KB Output is correct
14 Correct 115 ms 111344 KB Output is correct
15 Correct 114 ms 111384 KB Output is correct
16 Correct 116 ms 111380 KB Output is correct
17 Correct 143 ms 112596 KB Output is correct
18 Correct 125 ms 111352 KB Output is correct
19 Correct 115 ms 111372 KB Output is correct
20 Correct 115 ms 111676 KB Output is correct
21 Correct 115 ms 111604 KB Output is correct
22 Correct 124 ms 111372 KB Output is correct
23 Correct 118 ms 111384 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 170 ms 113644 KB Output is correct
26 Correct 149 ms 113416 KB Output is correct
27 Correct 124 ms 112364 KB Output is correct
28 Correct 138 ms 112796 KB Output is correct
29 Correct 198 ms 114160 KB Output is correct
30 Correct 141 ms 112932 KB Output is correct