Submission #721366

# Submission time Handle Problem Language Result Execution time Memory
721366 2023-04-10T18:47:59 Z gagik_2007 Uplifting Excursion (BOI22_vault) C++17
20 / 100
1650 ms 4180 KB
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <chrono>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <random>
#include <cassert>
using namespace std;

typedef long long ll;
typedef long double ld;

#define ff first
#define ss second

ll ttt;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll N = 100007;
const ll LG = 31;
ll n, m, k;
ll c[N];

int knapsack(vector<pair<int, int>>& a, int L) {
	ll sum = 0;
	ll mn = 0;
	for (auto x : a) {
		//cout << x.ff << " " << x.ss << endl;
		sum += abs(x.ff);
		mn += min(0, x.ff);
	}
	//cout << endl << endl;
	vector<int>dp(sum + 1, -MOD);
	dp[-mn] = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i].ff >= 0) {
			for (int j = sum; j - a[i].ff >= 0; j--) {
				dp[j] = max(dp[j], dp[j - a[i].ff] + a[i].ss);
			}
		}
		else {
			for (int j = 0; j - a[i].ff <= sum; j++) {
				dp[j] = max(dp[j], dp[j - a[i].ff] + a[i].ss);
			}
		}
		/*for (int j = 0; j <= sum; j++) {
			cout << j + mn << ": " << dp[j] << "\n";
		}
		cout << endl;*/
	}
	if (L - mn > sum)return -MOD;
	if (L - mn < 0)return -MOD;
	return dp[L - mn];
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	vector<pair<int, int>>a;
	ll cur = -n;
	for (int i = 0; i <= 2 * n; i++, cur++) {
		cin >> c[i];
		for (int j = LG; j >= 0; j--) {
			if (c[i] & (1ll << j)) {
				for (int p = j - 1; p >= 0; p--) {
					a.push_back({ cur * (1ll << p),(1ll << p) });
				}
				ll rem = c[i] - (1ll << j) + 1;
				a.push_back({ cur * rem,rem });
				break;
			}
		}
	}
	ll res = knapsack(a, k);
	if (res >= 0) {
		cout << res << endl;
	}
	else cout << "impossible\n";
}

/// ---- - --------  ------ -------- -- - - -
/// Just a reminder. Ubuntu password is I O I
/// ---- - --------  ------ -------- -- - - -

Compilation message

vault.cpp: In function 'int knapsack(std::vector<std::pair<int, int> >&, int)':
vault.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 39 ms 596 KB Output is correct
6 Correct 40 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 39 ms 468 KB Output is correct
9 Correct 87 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 39 ms 596 KB Output is correct
6 Correct 40 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 39 ms 468 KB Output is correct
9 Correct 87 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 41 ms 596 KB Output is correct
17 Correct 42 ms 596 KB Output is correct
18 Correct 10 ms 448 KB Output is correct
19 Correct 37 ms 468 KB Output is correct
20 Correct 88 ms 724 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 692 ms 2260 KB Output is correct
24 Correct 722 ms 2260 KB Output is correct
25 Correct 114 ms 1108 KB Output is correct
26 Correct 1650 ms 4176 KB Output is correct
27 Correct 1602 ms 4180 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 2 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 2 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 2 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 39 ms 596 KB Output is correct
6 Correct 40 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 39 ms 468 KB Output is correct
9 Correct 87 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Runtime error 2 ms 596 KB Execution killed with signal 6
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 2 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 39 ms 596 KB Output is correct
6 Correct 40 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 39 ms 468 KB Output is correct
9 Correct 87 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 41 ms 596 KB Output is correct
17 Correct 42 ms 596 KB Output is correct
18 Correct 10 ms 448 KB Output is correct
19 Correct 37 ms 468 KB Output is correct
20 Correct 88 ms 724 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 692 ms 2260 KB Output is correct
24 Correct 722 ms 2260 KB Output is correct
25 Correct 114 ms 1108 KB Output is correct
26 Correct 1650 ms 4176 KB Output is correct
27 Correct 1602 ms 4180 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Runtime error 2 ms 596 KB Execution killed with signal 6
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 2 ms 596 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 39 ms 596 KB Output is correct
6 Correct 40 ms 596 KB Output is correct
7 Correct 8 ms 340 KB Output is correct
8 Correct 39 ms 468 KB Output is correct
9 Correct 87 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 41 ms 596 KB Output is correct
17 Correct 42 ms 596 KB Output is correct
18 Correct 10 ms 448 KB Output is correct
19 Correct 37 ms 468 KB Output is correct
20 Correct 88 ms 724 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 692 ms 2260 KB Output is correct
24 Correct 722 ms 2260 KB Output is correct
25 Correct 114 ms 1108 KB Output is correct
26 Correct 1650 ms 4176 KB Output is correct
27 Correct 1602 ms 4180 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Runtime error 2 ms 596 KB Execution killed with signal 6
32 Halted 0 ms 0 KB -