답안 #925737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925737 2024-02-12T08:01:18 Z vjudge1 Kitchen (BOI19_kitchen) C++17
51 / 100
278 ms 5280 KB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" 	
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") 

#include <bits/stdc++.h>

#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e6 + 5, mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const ld eps = 1e-6;

ll add (ll a, ll b) {
	a += b;
	if (a < 0) a += mod;
	if (a >= mod) a -= mod;
	return a;
}

ll mul (ll a, ll b) {
	a *= b;
	if (a >= mod) a %= mod;
	return a;
}

int n, m, k, a[N], b[N], dp[N];

void solve () {
	cin >> n >> m >> k;
	int sum = 0;
	for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
	for (int i = 1; i <= m; i++) cin >> b[i];
	if (k == 1) {
		dp[0] = 1;
		for (int i = 1; i <= m; i++) {
			for (int w = 90000 - b[i]; w >= 0; w--) dp[w + b[i]] |= dp[w];
		}
		for (int i = sum; i <= 90000; i++) {
			if (dp[i]) cout << i - sum << '\n', exit(0);
		}
		cout << "Impossible\n";
		return;
	}
	int ans = inf;
	for (int mask = 0; mask < (1 << m); mask++) {
		int res = 0;
		vt<int> v;
		for (int i = 0; i < m; i++) {
			if (bit(mask, i)) v.pb(b[i + 1]), res += b[i + 1];
		}
		if (sz(v) < k) continue;
		sort(all(v)); reverse(all(v));
		bool ok = 1;
		for (int j = 1; j <= n && ok; j++) {
			if (a[j] < k) ok = 0;
			for (int i = 0; i < k && ok; i++) {
				if (v[i] == 0) ok = 0;
				v[i]--;
			}
			sort(all(v)); reverse(all(v));
		}
		res -= sum;
		if (ok && res >= 0) ans = min(ans, res);
	}
	if (k > m || ans == inf) cout << "Impossible\n", exit(0);
	cout << ans;
	cout << '\n';
}

bool testcases = 0;

signed main() {
#ifdef AMIR
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
	cin.tie(0) -> sync_with_stdio(0);
	int test = 1;
	if (testcases) cin >> test;
	for (int cs = 1; cs <= test; cs++) {
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 1 ms 5208 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 1 ms 5208 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 9 ms 4444 KB Output is correct
10 Correct 11 ms 4564 KB Output is correct
11 Correct 6 ms 4444 KB Output is correct
12 Correct 32 ms 4444 KB Output is correct
13 Correct 278 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 5212 KB Output is correct
2 Correct 15 ms 5280 KB Output is correct
3 Correct 20 ms 5276 KB Output is correct
4 Correct 20 ms 5212 KB Output is correct
5 Correct 19 ms 5280 KB Output is correct
6 Correct 14 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 1 ms 5208 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 5212 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 9 ms 4444 KB Output is correct
10 Correct 11 ms 4564 KB Output is correct
11 Correct 6 ms 4444 KB Output is correct
12 Correct 32 ms 4444 KB Output is correct
13 Correct 278 ms 4688 KB Output is correct
14 Correct 17 ms 5212 KB Output is correct
15 Correct 15 ms 5280 KB Output is correct
16 Correct 20 ms 5276 KB Output is correct
17 Correct 20 ms 5212 KB Output is correct
18 Correct 19 ms 5280 KB Output is correct
19 Correct 14 ms 5212 KB Output is correct
20 Incorrect 1 ms 4440 KB Output isn't correct
21 Halted 0 ms 0 KB -