답안 #862390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
862390 2023-10-18T07:42:30 Z iskhakkutbilim Kitchen (BOI19_kitchen) C++17
51 / 100
19 ms 1360 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
 
const int mod = 1e17;
const int N = 300;
int can[300 * 300 + 10];
 
int goal(vector<int> &srt, int k){
	int cnt = 0;
	while(true){
		sort(srt.rbegin(), srt.rend());
		if(srt[k-1] <= 0){
			break;
		}
		int mn = srt[k-1];
		for(int i = 0;i < k; i++){
			srt[i]-= mn;
		}
		cnt+= mn;
	}
	return cnt;
}
 
main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int n, m, k; 
	vector<int> a, b;
	cin >> n >> m >> k;
	a.resize(n);
	for(auto &e : a) cin >> e;
	b.resize(m);
	for(auto &e : b) cin >> e;
	int ans = mod;
	if(k > m or *min_element(all(a)) < k){
		cout << "Impossible";
		return 0;
	}
	can[0] = 1;
	for(int x : b){
		for(int i = N*N; i - x >= 0; i--){
			can[i]|= can[i-x];
		}
	}
	if(k == 1 && m > 15){
		
		int sumX = accumulate(all(a), 0LL);
		if(goal(b, k) < n){
			cout << "Impossible";
			return 0;
		}
		for(int i = sumX; i <= N*N; i++){
			if(can[i]){
				cout << i-sumX;
				return 0;
			}
		}
		cout << "Impossible";
		return 0;
	}
	for(int all = 0; all < (1<<m); all++){
		if(__builtin_popcount(all) < k) continue;
		int sumB = 0;
		int sumX = accumulate(all(a), 0LL);
		vector<int> srt;
		for(int i = 0;i < m; i++){
			if(all & (1<<i)){
				srt.push_back(b[i]);
				sumB+= b[i];
			}
		}
		if(goal(srt, k) < n){
			continue;
		}
		sumB = sumB - n * k;
		sumX = sumX - n * k;
		if(sumB >= sumX && sumX >= 0 && sumB >= 0){
			ans = min(ans, sumB - sumX);
		}
	}
	if(ans >= mod){
		cout << "Impossible";
		return 0;
	}
	cout << ans;
	return 0;
}

Compilation message

kitchen.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 8 ms 1116 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 12 ms 976 KB Output is correct
13 Correct 13 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 1360 KB Output is correct
2 Correct 14 ms 1112 KB Output is correct
3 Correct 19 ms 1116 KB Output is correct
4 Correct 19 ms 1116 KB Output is correct
5 Correct 18 ms 1116 KB Output is correct
6 Correct 13 ms 1168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 8 ms 1116 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 12 ms 976 KB Output is correct
13 Correct 13 ms 1116 KB Output is correct
14 Correct 18 ms 1360 KB Output is correct
15 Correct 14 ms 1112 KB Output is correct
16 Correct 19 ms 1116 KB Output is correct
17 Correct 19 ms 1116 KB Output is correct
18 Correct 18 ms 1116 KB Output is correct
19 Correct 13 ms 1168 KB Output is correct
20 Incorrect 3 ms 1112 KB Output isn't correct
21 Halted 0 ms 0 KB -