Submission #126129

# Submission time Handle Problem Language Result Execution time Memory
126129 2019-07-07T05:37:47 Z mechfrog88 Kitchen (BOI19_kitchen) C++14
51 / 100
1000 ms 2040 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;

ll n,m,k;
ll ans = LLONG_MAX;
vector <ll> chef;
vector <ll> arr;

void func(vector <ll> temp,ll index){
	if (index == m && temp.size() >= k){
		bool ok = true;
		ll left = 0;
		ll c = 0;
		while (c < arr.size() && ok){
			sort(temp.rbegin(),temp.rend());
			ll count = 0;
			for (int z=0;count<k;z++){
				while (temp[z] == 0 && z < temp.size()){
					z++;
				}
				if (z == temp.size()){
					ok = false;
					break;
				}
				count++;
				temp[z]--;
			}
			if (arr[c] < k){
				ok = false;
				break;
			} 
			left += arr[c]-k;
			c++;
		}
		ll s = 0;
		for (int z=0;z<temp.size();z++){
			s += temp[z];
		}
		if (s >= left && ok) ans = min(ans,s-left);
		return;
	}
	if (index == m) return;
	func(temp,index+1);
	temp.push_back(chef[index]);
	func(temp,index+1);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> k;
	arr.resize(n);
	ll s = 0;
	for (int z=0;z<n;z++){
		cin >> arr[z];
		s += arr[z];
	}
	chef.resize(m);
	for (int z=0;z<m;z++){
		cin >> chef[z];
	}
	if (k == 1){
		vector <bool> ok(90001,false);
		ok[0] = true;
		ok[chef[0]] = true;
		for (int z=1;z<m;z++){
			vector <ll> temp;
			for (int x=0;x<=90000;x++){
				if (ok[x] && x+chef[z] <= 90000) {
					temp.push_back(x+chef[z]);
				}
			}
			for (ll i : temp){
				ok[i] = true;
			}
		}
		ll ans = -1;
		ll c = 0;
		for (int z=s;z<=90000;z++){
			if (ok[z]) {
				ans = z;
				break;
			}
			c++; 
		}
		if (ans == -1) cout << "Impossible" << endl;
		else cout << ans-s << endl;
		return 0; 
	}
	vector <ll> temp;
	func(temp,0);
	if (ans == LLONG_MAX){
		cout << "Impossible" << endl;
	} else {
		cout << ans << endl;
	}
}

Compilation message

kitchen.cpp: In function 'void func(std::vector<long long int>, ll)':
kitchen.cpp:22:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (index == m && temp.size() >= k){
                    ~~~~~~~~~~~~^~~~
kitchen.cpp:26:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (c < arr.size() && ok){
          ~~^~~~~~~~~~~~
kitchen.cpp:30:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (temp[z] == 0 && z < temp.size()){
                            ~~^~~~~~~~~~~~~
kitchen.cpp:33:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (z == temp.size()){
         ~~^~~~~~~~~~~~~~
kitchen.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int z=0;z<temp.size();z++){
                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 412 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 412 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 11 ms 376 KB Output is correct
10 Correct 13 ms 384 KB Output is correct
11 Correct 8 ms 376 KB Output is correct
12 Correct 40 ms 392 KB Output is correct
13 Correct 312 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 884 KB Output is correct
2 Correct 52 ms 908 KB Output is correct
3 Correct 139 ms 1292 KB Output is correct
4 Correct 212 ms 2040 KB Output is correct
5 Correct 176 ms 2036 KB Output is correct
6 Correct 46 ms 836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1016 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 412 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 11 ms 376 KB Output is correct
10 Correct 13 ms 384 KB Output is correct
11 Correct 8 ms 376 KB Output is correct
12 Correct 40 ms 392 KB Output is correct
13 Correct 312 ms 392 KB Output is correct
14 Correct 66 ms 884 KB Output is correct
15 Correct 52 ms 908 KB Output is correct
16 Correct 139 ms 1292 KB Output is correct
17 Correct 212 ms 2040 KB Output is correct
18 Correct 176 ms 2036 KB Output is correct
19 Correct 46 ms 836 KB Output is correct
20 Execution timed out 1016 ms 376 KB Time limit exceeded
21 Halted 0 ms 0 KB -