Submission #592104

# Submission time Handle Problem Language Result Execution time Memory
592104 2022-07-08T13:47:35 Z tutis Uplifting Excursion (BOI22_vault) C++17
45 / 100
5000 ms 63232 KB
/*input
2 5
2 3 1 1 4

*/

#pragma GCC optimize ("O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T,  null_type,  less<T>,  rb_tree_tag,  tree_order_statistics_node_update>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 rng(0);
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int M;
	ll L;
	cin >> M >> L;
	ll A_[2 * M + 1];
	ll* A = A_ + M;
	for (int i = -M; i <= M; i++)
		cin >> A[i];
	ll pl = 0;
	pl += A[0];
	A[0] = 0;
	L = -L;
	ll cnt = 0;
	for (int l = -M; l <= M; l++)
	{
		L += l * A[l];
		cnt += A[l];
	}
	cc_hash_table<ll, ll>D;
	D[0] = 0;
	ll del = M;
	A[0] = 1;
	for (int v = M; v >= 1; v--)
		for (int l : {v, -v})
		{
			if (l == 0)
				continue;
			cc_hash_table<ll, ll>D_;
			for (pair<ll, ll>v : D)
			{
				ll k = (L - v.first) / l;
				k = max(k, 0ll);
				k = min(k, A[l]);
				ll lo = max(0ll, k - del);
				ll hi = min(k + del, A[l]);
				if (abs(L - (v.first + k * l)) < abs(l) && A[L - (v.first + k * l)] > 0)
				{
					ll v_ = v.first + l * k;
					ll c_ = v.second + k;
					auto it = D_.find(v_);
					if (it == D_.end())
						D_[v_] = c_;
					else
						it->second = min(it->second, c_);
				}
				else
					for (ll c = lo; c <= hi; c++)
					{
						ll v_ = v.first + l * c;
						ll c_ = v.second + c;
						auto it = D_.find(v_);
						if (it == D_.end())
							D_[v_] = c_;
						else
							it->second = min(it->second, c_);
					}
			}
			D = D_;
		}
	if (D.find(L) != D.end())
		cout << pl + cnt - D[L] << "\n";
	else
		cout << "impossible\n";
}
# 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1174 ms 9504 KB Output is correct
6 Correct 1193 ms 15652 KB Output is correct
7 Correct 362 ms 4708 KB Output is correct
8 Correct 1025 ms 8992 KB Output is correct
9 Correct 3105 ms 17604 KB Output is correct
10 Correct 34 ms 816 KB Output is correct
11 Correct 38 ms 832 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1174 ms 9504 KB Output is correct
6 Correct 1193 ms 15652 KB Output is correct
7 Correct 362 ms 4708 KB Output is correct
8 Correct 1025 ms 8992 KB Output is correct
9 Correct 3105 ms 17604 KB Output is correct
10 Correct 34 ms 816 KB Output is correct
11 Correct 38 ms 832 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1199 ms 9508 KB Output is correct
17 Correct 1215 ms 15804 KB Output is correct
18 Correct 353 ms 4748 KB Output is correct
19 Correct 1000 ms 9044 KB Output is correct
20 Correct 3089 ms 17700 KB Output is correct
21 Correct 33 ms 812 KB Output is correct
22 Correct 36 ms 832 KB Output is correct
23 Execution timed out 5067 ms 63232 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 26 ms 1396 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 46 ms 1420 KB Output is correct
7 Correct 11 ms 572 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 10 ms 724 KB Output is correct
10 Correct 22 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 26 ms 1396 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 46 ms 1420 KB Output is correct
7 Correct 11 ms 572 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 10 ms 724 KB Output is correct
10 Correct 22 ms 1236 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 18 ms 852 KB Output is correct
17 Correct 26 ms 1404 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 48 ms 1364 KB Output is correct
20 Correct 10 ms 540 KB Output is correct
21 Correct 10 ms 468 KB Output is correct
22 Correct 10 ms 724 KB Output is correct
23 Correct 21 ms 1144 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 63 ms 2280 KB Output is correct
26 Correct 230 ms 4564 KB Output is correct
27 Correct 27 ms 1332 KB Output is correct
28 Correct 176 ms 4292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 26 ms 1396 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 46 ms 1420 KB Output is correct
7 Correct 11 ms 572 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 10 ms 724 KB Output is correct
10 Correct 22 ms 1236 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 18 ms 852 KB Output is correct
14 Correct 26 ms 1396 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 48 ms 1368 KB Output is correct
17 Correct 10 ms 544 KB Output is correct
18 Correct 11 ms 592 KB Output is correct
19 Correct 10 ms 724 KB Output is correct
20 Correct 23 ms 1232 KB Output is correct
21 Correct 33 ms 792 KB Output is correct
22 Correct 36 ms 780 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 314 ms 4608 KB Output is correct
25 Correct 545 ms 8500 KB Output is correct
26 Correct 321 ms 8584 KB Output is correct
27 Correct 708 ms 8728 KB Output is correct
28 Correct 283 ms 4568 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1174 ms 9504 KB Output is correct
6 Correct 1193 ms 15652 KB Output is correct
7 Correct 362 ms 4708 KB Output is correct
8 Correct 1025 ms 8992 KB Output is correct
9 Correct 3105 ms 17604 KB Output is correct
10 Correct 34 ms 816 KB Output is correct
11 Correct 38 ms 832 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 18 ms 852 KB Output is correct
15 Correct 26 ms 1396 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 46 ms 1420 KB Output is correct
18 Correct 11 ms 572 KB Output is correct
19 Correct 10 ms 468 KB Output is correct
20 Correct 10 ms 724 KB Output is correct
21 Correct 22 ms 1236 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 18 ms 852 KB Output is correct
28 Correct 26 ms 1404 KB Output is correct
29 Correct 2 ms 724 KB Output is correct
30 Correct 48 ms 1364 KB Output is correct
31 Correct 10 ms 540 KB Output is correct
32 Correct 10 ms 468 KB Output is correct
33 Correct 10 ms 724 KB Output is correct
34 Correct 21 ms 1144 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 63 ms 2280 KB Output is correct
37 Correct 230 ms 4564 KB Output is correct
38 Correct 27 ms 1332 KB Output is correct
39 Correct 176 ms 4292 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 18 ms 852 KB Output is correct
43 Correct 26 ms 1396 KB Output is correct
44 Correct 2 ms 724 KB Output is correct
45 Correct 48 ms 1368 KB Output is correct
46 Correct 10 ms 544 KB Output is correct
47 Correct 11 ms 592 KB Output is correct
48 Correct 10 ms 724 KB Output is correct
49 Correct 23 ms 1232 KB Output is correct
50 Correct 33 ms 792 KB Output is correct
51 Correct 36 ms 780 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 314 ms 4608 KB Output is correct
54 Correct 545 ms 8500 KB Output is correct
55 Correct 321 ms 8584 KB Output is correct
56 Correct 708 ms 8728 KB Output is correct
57 Correct 283 ms 4568 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1164 ms 9524 KB Output is correct
63 Correct 1167 ms 15676 KB Output is correct
64 Correct 345 ms 4980 KB Output is correct
65 Correct 992 ms 9016 KB Output is correct
66 Correct 3086 ms 17816 KB Output is correct
67 Correct 33 ms 816 KB Output is correct
68 Correct 36 ms 832 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 17 ms 852 KB Output is correct
71 Correct 25 ms 1388 KB Output is correct
72 Correct 2 ms 724 KB Output is correct
73 Correct 49 ms 1472 KB Output is correct
74 Correct 11 ms 468 KB Output is correct
75 Correct 11 ms 596 KB Output is correct
76 Correct 10 ms 724 KB Output is correct
77 Correct 21 ms 1148 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 63 ms 2212 KB Output is correct
80 Correct 234 ms 4580 KB Output is correct
81 Correct 27 ms 1332 KB Output is correct
82 Correct 180 ms 4284 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 313 ms 4620 KB Output is correct
85 Correct 544 ms 8628 KB Output is correct
86 Correct 321 ms 8564 KB Output is correct
87 Correct 700 ms 8980 KB Output is correct
88 Correct 282 ms 4608 KB Output is correct
89 Correct 1 ms 212 KB Output is correct
90 Correct 13 ms 2248 KB Output is correct
91 Correct 487 ms 9168 KB Output is correct
92 Correct 1947 ms 17388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 26 ms 1396 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 46 ms 1420 KB Output is correct
7 Correct 11 ms 572 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 10 ms 724 KB Output is correct
10 Correct 22 ms 1236 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 18 ms 852 KB Output is correct
14 Correct 26 ms 1396 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 48 ms 1368 KB Output is correct
17 Correct 10 ms 544 KB Output is correct
18 Correct 11 ms 592 KB Output is correct
19 Correct 10 ms 724 KB Output is correct
20 Correct 23 ms 1232 KB Output is correct
21 Correct 33 ms 792 KB Output is correct
22 Correct 36 ms 780 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 314 ms 4608 KB Output is correct
25 Correct 545 ms 8500 KB Output is correct
26 Correct 321 ms 8584 KB Output is correct
27 Correct 708 ms 8728 KB Output is correct
28 Correct 283 ms 4568 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 17 ms 852 KB Output is correct
32 Correct 26 ms 1396 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 48 ms 1400 KB Output is correct
35 Correct 10 ms 468 KB Output is correct
36 Correct 10 ms 496 KB Output is correct
37 Correct 11 ms 724 KB Output is correct
38 Correct 21 ms 1228 KB Output is correct
39 Correct 33 ms 832 KB Output is correct
40 Correct 39 ms 832 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 325 ms 4576 KB Output is correct
43 Correct 543 ms 8332 KB Output is correct
44 Correct 331 ms 8544 KB Output is correct
45 Correct 703 ms 8780 KB Output is correct
46 Correct 281 ms 4744 KB Output is correct
47 Correct 267 ms 2416 KB Output is correct
48 Correct 273 ms 2244 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 4392 ms 33020 KB Output is correct
51 Execution timed out 5051 ms 34988 KB Time limit exceeded
52 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1174 ms 9504 KB Output is correct
6 Correct 1193 ms 15652 KB Output is correct
7 Correct 362 ms 4708 KB Output is correct
8 Correct 1025 ms 8992 KB Output is correct
9 Correct 3105 ms 17604 KB Output is correct
10 Correct 34 ms 816 KB Output is correct
11 Correct 38 ms 832 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1199 ms 9508 KB Output is correct
17 Correct 1215 ms 15804 KB Output is correct
18 Correct 353 ms 4748 KB Output is correct
19 Correct 1000 ms 9044 KB Output is correct
20 Correct 3089 ms 17700 KB Output is correct
21 Correct 33 ms 812 KB Output is correct
22 Correct 36 ms 832 KB Output is correct
23 Execution timed out 5067 ms 63232 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 18 ms 852 KB Output is correct
4 Correct 26 ms 1396 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 46 ms 1420 KB Output is correct
7 Correct 11 ms 572 KB Output is correct
8 Correct 10 ms 468 KB Output is correct
9 Correct 10 ms 724 KB Output is correct
10 Correct 22 ms 1236 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 18 ms 852 KB Output is correct
14 Correct 26 ms 1396 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 48 ms 1368 KB Output is correct
17 Correct 10 ms 544 KB Output is correct
18 Correct 11 ms 592 KB Output is correct
19 Correct 10 ms 724 KB Output is correct
20 Correct 23 ms 1232 KB Output is correct
21 Correct 33 ms 792 KB Output is correct
22 Correct 36 ms 780 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 314 ms 4608 KB Output is correct
25 Correct 545 ms 8500 KB Output is correct
26 Correct 321 ms 8584 KB Output is correct
27 Correct 708 ms 8728 KB Output is correct
28 Correct 283 ms 4568 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 17 ms 852 KB Output is correct
32 Correct 26 ms 1396 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 48 ms 1400 KB Output is correct
35 Correct 10 ms 468 KB Output is correct
36 Correct 10 ms 496 KB Output is correct
37 Correct 11 ms 724 KB Output is correct
38 Correct 21 ms 1228 KB Output is correct
39 Correct 33 ms 832 KB Output is correct
40 Correct 39 ms 832 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 325 ms 4576 KB Output is correct
43 Correct 543 ms 8332 KB Output is correct
44 Correct 331 ms 8544 KB Output is correct
45 Correct 703 ms 8780 KB Output is correct
46 Correct 281 ms 4744 KB Output is correct
47 Correct 267 ms 2416 KB Output is correct
48 Correct 273 ms 2244 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 4392 ms 33020 KB Output is correct
51 Execution timed out 5051 ms 34988 KB Time limit exceeded
52 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 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1174 ms 9504 KB Output is correct
6 Correct 1193 ms 15652 KB Output is correct
7 Correct 362 ms 4708 KB Output is correct
8 Correct 1025 ms 8992 KB Output is correct
9 Correct 3105 ms 17604 KB Output is correct
10 Correct 34 ms 816 KB Output is correct
11 Correct 38 ms 832 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1199 ms 9508 KB Output is correct
17 Correct 1215 ms 15804 KB Output is correct
18 Correct 353 ms 4748 KB Output is correct
19 Correct 1000 ms 9044 KB Output is correct
20 Correct 3089 ms 17700 KB Output is correct
21 Correct 33 ms 812 KB Output is correct
22 Correct 36 ms 832 KB Output is correct
23 Execution timed out 5067 ms 63232 KB Time limit exceeded
24 Halted 0 ms 0 KB -