Submission #592125

# Submission time Handle Problem Language Result Execution time Memory
592125 2022-07-08T14:55:55 Z tutis Uplifting Excursion (BOI22_vault) C++17
45 / 100
5000 ms 85332 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;
	cc_hash_table<ll, int>X[M + 1];
	X[0][0] = 0;
	int mxe = 50;
	for (int v = 1; v <= M; v++)
	{
		for (pair<ll, int>a : X[v - 1])
		{
			int mxe1 = mxe - a.second;
			for (int l : {v, -v})
			{
				for (int i = 0; i <= mxe1 && i <= A[l]; i++)
				{
					ll val = a.first + i * l;
					int ej = a.second + i;
					auto it = X[v].find(val);
					if (it == X[v].end())
						X[v][val] = ej;
					else
						it->second = min(it->second, ej);
				}
			}
		}
	}
	if (X[M].find(L) != X[M].end())
	{
		cout << pl + cnt - X[M][L] << "\n";
		return 0;
	}
	ll infi = 5e18;
	ll best = infi;
	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)
			{
				if (v.second >= best)
					continue;
				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)
				{
					int d = 1;
					if (L - (v.first + k * l) == 0)
						d = 0;
					ll c_ = v.second + k + d;
					best = min(best, c_);
				}
				else
				{
					for (ll c = lo; c <= hi; c++)
					{
						ll v_ = v.first + l * c;
						ll c_ = v.second + c;
						if (c_ >= best)
							continue;
						auto it1 = X[abs(l) - 1].find(L - v_);
						if (it1 != X[abs(l) - 1].end())
						{
							best = min(best, c_ + it1->second);
						}
						else {
							auto it = D_.find(v_);
							if (it == D_.end())
								D_[v_] = c_;
							else
								it->second = min(it->second, c_);
						}
					}
				}
			}
			D = D_;
		}
	if (best < infi)
		cout << pl + cnt - best << "\n";
	else
		cout << "impossible\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1482 ms 16348 KB Output is correct
6 Correct 46 ms 7176 KB Output is correct
7 Correct 418 ms 10880 KB Output is correct
8 Correct 1109 ms 15336 KB Output is correct
9 Correct 3772 ms 24824 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1482 ms 16348 KB Output is correct
6 Correct 46 ms 7176 KB Output is correct
7 Correct 418 ms 10880 KB Output is correct
8 Correct 1109 ms 15336 KB Output is correct
9 Correct 3772 ms 24824 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1478 ms 16460 KB Output is correct
17 Correct 44 ms 7144 KB Output is correct
18 Correct 413 ms 10896 KB Output is correct
19 Correct 1106 ms 15396 KB Output is correct
20 Correct 3754 ms 24988 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 448 KB Output is correct
23 Execution timed out 5056 ms 85332 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 6 ms 1520 KB Output is correct
3 Correct 25 ms 1704 KB Output is correct
4 Correct 37 ms 2528 KB Output is correct
5 Correct 8 ms 1916 KB Output is correct
6 Correct 55 ms 2588 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 6 ms 1520 KB Output is correct
3 Correct 25 ms 1704 KB Output is correct
4 Correct 37 ms 2528 KB Output is correct
5 Correct 8 ms 1916 KB Output is correct
6 Correct 55 ms 2588 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 1364 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 1 ms 340 KB Output is correct
15 Correct 5 ms 1492 KB Output is correct
16 Correct 23 ms 1744 KB Output is correct
17 Correct 37 ms 2624 KB Output is correct
18 Correct 8 ms 2004 KB Output is correct
19 Correct 55 ms 2516 KB Output is correct
20 Correct 7 ms 652 KB Output is correct
21 Correct 6 ms 596 KB Output is correct
22 Correct 3 ms 1236 KB Output is correct
23 Correct 4 ms 1364 KB Output is correct
24 Correct 16 ms 2768 KB Output is correct
25 Correct 78 ms 4400 KB Output is correct
26 Correct 308 ms 7172 KB Output is correct
27 Correct 15 ms 2644 KB Output is correct
28 Correct 217 ms 6752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 6 ms 1520 KB Output is correct
3 Correct 25 ms 1704 KB Output is correct
4 Correct 37 ms 2528 KB Output is correct
5 Correct 8 ms 1916 KB Output is correct
6 Correct 55 ms 2588 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 1364 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 1492 KB Output is correct
13 Correct 24 ms 1748 KB Output is correct
14 Correct 36 ms 2636 KB Output is correct
15 Correct 8 ms 2004 KB Output is correct
16 Correct 57 ms 2488 KB Output is correct
17 Correct 7 ms 644 KB Output is correct
18 Correct 7 ms 580 KB Output is correct
19 Correct 3 ms 1236 KB Output is correct
20 Correct 4 ms 1364 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 16 ms 3668 KB Output is correct
24 Correct 387 ms 7732 KB Output is correct
25 Correct 16 ms 3924 KB Output is correct
26 Correct 405 ms 11840 KB Output is correct
27 Correct 829 ms 12332 KB Output is correct
28 Correct 16 ms 3668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1482 ms 16348 KB Output is correct
6 Correct 46 ms 7176 KB Output is correct
7 Correct 418 ms 10880 KB Output is correct
8 Correct 1109 ms 15336 KB Output is correct
9 Correct 3772 ms 24824 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 6 ms 1520 KB Output is correct
14 Correct 25 ms 1704 KB Output is correct
15 Correct 37 ms 2528 KB Output is correct
16 Correct 8 ms 1916 KB Output is correct
17 Correct 55 ms 2588 KB Output is correct
18 Correct 7 ms 596 KB Output is correct
19 Correct 6 ms 596 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Correct 4 ms 1364 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 5 ms 1492 KB Output is correct
27 Correct 23 ms 1744 KB Output is correct
28 Correct 37 ms 2624 KB Output is correct
29 Correct 8 ms 2004 KB Output is correct
30 Correct 55 ms 2516 KB Output is correct
31 Correct 7 ms 652 KB Output is correct
32 Correct 6 ms 596 KB Output is correct
33 Correct 3 ms 1236 KB Output is correct
34 Correct 4 ms 1364 KB Output is correct
35 Correct 16 ms 2768 KB Output is correct
36 Correct 78 ms 4400 KB Output is correct
37 Correct 308 ms 7172 KB Output is correct
38 Correct 15 ms 2644 KB Output is correct
39 Correct 217 ms 6752 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 6 ms 1492 KB Output is correct
42 Correct 24 ms 1748 KB Output is correct
43 Correct 36 ms 2636 KB Output is correct
44 Correct 8 ms 2004 KB Output is correct
45 Correct 57 ms 2488 KB Output is correct
46 Correct 7 ms 644 KB Output is correct
47 Correct 7 ms 580 KB Output is correct
48 Correct 3 ms 1236 KB Output is correct
49 Correct 4 ms 1364 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 468 KB Output is correct
52 Correct 16 ms 3668 KB Output is correct
53 Correct 387 ms 7732 KB Output is correct
54 Correct 16 ms 3924 KB Output is correct
55 Correct 405 ms 11840 KB Output is correct
56 Correct 829 ms 12332 KB Output is correct
57 Correct 16 ms 3668 KB Output is correct
58 Correct 1 ms 320 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1467 ms 16352 KB Output is correct
63 Correct 42 ms 7124 KB Output is correct
64 Correct 414 ms 11192 KB Output is correct
65 Correct 1127 ms 15432 KB Output is correct
66 Correct 3804 ms 24816 KB Output is correct
67 Correct 1 ms 468 KB Output is correct
68 Correct 1 ms 468 KB Output is correct
69 Correct 5 ms 1492 KB Output is correct
70 Correct 22 ms 1712 KB Output is correct
71 Correct 34 ms 2620 KB Output is correct
72 Correct 8 ms 2024 KB Output is correct
73 Correct 55 ms 2556 KB Output is correct
74 Correct 7 ms 596 KB Output is correct
75 Correct 6 ms 596 KB Output is correct
76 Correct 3 ms 1236 KB Output is correct
77 Correct 4 ms 1364 KB Output is correct
78 Correct 15 ms 2644 KB Output is correct
79 Correct 83 ms 4400 KB Output is correct
80 Correct 282 ms 7164 KB Output is correct
81 Correct 17 ms 2704 KB Output is correct
82 Correct 236 ms 6676 KB Output is correct
83 Correct 18 ms 3668 KB Output is correct
84 Correct 375 ms 7736 KB Output is correct
85 Correct 17 ms 3924 KB Output is correct
86 Correct 393 ms 11884 KB Output is correct
87 Correct 813 ms 12392 KB Output is correct
88 Correct 19 ms 3668 KB Output is correct
89 Correct 49 ms 7244 KB Output is correct
90 Correct 76 ms 9280 KB Output is correct
91 Correct 610 ms 15976 KB Output is correct
92 Correct 2436 ms 24248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 6 ms 1520 KB Output is correct
3 Correct 25 ms 1704 KB Output is correct
4 Correct 37 ms 2528 KB Output is correct
5 Correct 8 ms 1916 KB Output is correct
6 Correct 55 ms 2588 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 1364 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 1492 KB Output is correct
13 Correct 24 ms 1748 KB Output is correct
14 Correct 36 ms 2636 KB Output is correct
15 Correct 8 ms 2004 KB Output is correct
16 Correct 57 ms 2488 KB Output is correct
17 Correct 7 ms 644 KB Output is correct
18 Correct 7 ms 580 KB Output is correct
19 Correct 3 ms 1236 KB Output is correct
20 Correct 4 ms 1364 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 16 ms 3668 KB Output is correct
24 Correct 387 ms 7732 KB Output is correct
25 Correct 16 ms 3924 KB Output is correct
26 Correct 405 ms 11840 KB Output is correct
27 Correct 829 ms 12332 KB Output is correct
28 Correct 16 ms 3668 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 6 ms 1556 KB Output is correct
31 Correct 23 ms 1728 KB Output is correct
32 Correct 41 ms 2632 KB Output is correct
33 Correct 8 ms 2004 KB Output is correct
34 Correct 57 ms 2600 KB Output is correct
35 Correct 8 ms 596 KB Output is correct
36 Correct 8 ms 596 KB Output is correct
37 Correct 3 ms 1236 KB Output is correct
38 Correct 4 ms 1364 KB Output is correct
39 Correct 1 ms 372 KB Output is correct
40 Correct 1 ms 448 KB Output is correct
41 Correct 18 ms 3796 KB Output is correct
42 Correct 362 ms 7760 KB Output is correct
43 Correct 16 ms 3924 KB Output is correct
44 Correct 425 ms 11872 KB Output is correct
45 Correct 816 ms 12244 KB Output is correct
46 Correct 18 ms 3684 KB Output is correct
47 Correct 142 ms 1528 KB Output is correct
48 Correct 140 ms 1592 KB Output is correct
49 Correct 64 ms 14028 KB Output is correct
50 Execution timed out 5029 ms 46092 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1482 ms 16348 KB Output is correct
6 Correct 46 ms 7176 KB Output is correct
7 Correct 418 ms 10880 KB Output is correct
8 Correct 1109 ms 15336 KB Output is correct
9 Correct 3772 ms 24824 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1478 ms 16460 KB Output is correct
17 Correct 44 ms 7144 KB Output is correct
18 Correct 413 ms 10896 KB Output is correct
19 Correct 1106 ms 15396 KB Output is correct
20 Correct 3754 ms 24988 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 448 KB Output is correct
23 Execution timed out 5056 ms 85332 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 6 ms 1520 KB Output is correct
3 Correct 25 ms 1704 KB Output is correct
4 Correct 37 ms 2528 KB Output is correct
5 Correct 8 ms 1916 KB Output is correct
6 Correct 55 ms 2588 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 4 ms 1364 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 1492 KB Output is correct
13 Correct 24 ms 1748 KB Output is correct
14 Correct 36 ms 2636 KB Output is correct
15 Correct 8 ms 2004 KB Output is correct
16 Correct 57 ms 2488 KB Output is correct
17 Correct 7 ms 644 KB Output is correct
18 Correct 7 ms 580 KB Output is correct
19 Correct 3 ms 1236 KB Output is correct
20 Correct 4 ms 1364 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 16 ms 3668 KB Output is correct
24 Correct 387 ms 7732 KB Output is correct
25 Correct 16 ms 3924 KB Output is correct
26 Correct 405 ms 11840 KB Output is correct
27 Correct 829 ms 12332 KB Output is correct
28 Correct 16 ms 3668 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 6 ms 1556 KB Output is correct
31 Correct 23 ms 1728 KB Output is correct
32 Correct 41 ms 2632 KB Output is correct
33 Correct 8 ms 2004 KB Output is correct
34 Correct 57 ms 2600 KB Output is correct
35 Correct 8 ms 596 KB Output is correct
36 Correct 8 ms 596 KB Output is correct
37 Correct 3 ms 1236 KB Output is correct
38 Correct 4 ms 1364 KB Output is correct
39 Correct 1 ms 372 KB Output is correct
40 Correct 1 ms 448 KB Output is correct
41 Correct 18 ms 3796 KB Output is correct
42 Correct 362 ms 7760 KB Output is correct
43 Correct 16 ms 3924 KB Output is correct
44 Correct 425 ms 11872 KB Output is correct
45 Correct 816 ms 12244 KB Output is correct
46 Correct 18 ms 3684 KB Output is correct
47 Correct 142 ms 1528 KB Output is correct
48 Correct 140 ms 1592 KB Output is correct
49 Correct 64 ms 14028 KB Output is correct
50 Execution timed out 5029 ms 46092 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1482 ms 16348 KB Output is correct
6 Correct 46 ms 7176 KB Output is correct
7 Correct 418 ms 10880 KB Output is correct
8 Correct 1109 ms 15336 KB Output is correct
9 Correct 3772 ms 24824 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 1478 ms 16460 KB Output is correct
17 Correct 44 ms 7144 KB Output is correct
18 Correct 413 ms 10896 KB Output is correct
19 Correct 1106 ms 15396 KB Output is correct
20 Correct 3754 ms 24988 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 448 KB Output is correct
23 Execution timed out 5056 ms 85332 KB Time limit exceeded
24 Halted 0 ms 0 KB -