Submission #721364

# Submission time Handle Problem Language Result Execution time Memory
721364 2023-04-10T18:46:18 Z gagik_2007 Uplifting Excursion (BOI22_vault) C++17
5 / 100
737 ms 4508 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;
	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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 42 ms 596 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 37 ms 596 KB Output is correct
9 Correct 89 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 42 ms 596 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 37 ms 596 KB Output is correct
9 Correct 89 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 268 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 38 ms 596 KB Output is correct
17 Correct 42 ms 588 KB Output is correct
18 Correct 8 ms 444 KB Output is correct
19 Correct 37 ms 592 KB Output is correct
20 Correct 97 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 Runtime error 737 ms 4508 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 42 ms 596 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 37 ms 596 KB Output is correct
9 Correct 89 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 42 ms 596 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 37 ms 596 KB Output is correct
9 Correct 89 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 268 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 38 ms 596 KB Output is correct
17 Correct 42 ms 588 KB Output is correct
18 Correct 8 ms 444 KB Output is correct
19 Correct 37 ms 592 KB Output is correct
20 Correct 97 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 Runtime error 737 ms 4508 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 42 ms 596 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 37 ms 596 KB Output is correct
9 Correct 89 ms 724 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 268 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 38 ms 596 KB Output is correct
17 Correct 42 ms 588 KB Output is correct
18 Correct 8 ms 444 KB Output is correct
19 Correct 37 ms 592 KB Output is correct
20 Correct 97 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 Runtime error 737 ms 4508 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -