Submission #579224

# Submission time Handle Problem Language Result Execution time Memory
579224 2022-06-18T13:43:44 Z cheissmart Uplifting Excursion (BOI22_vault) C++14
45 / 100
5000 ms 3284 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7, mxM = 303;

template<class T> void cmax(T& a, T b) { a = max(a, b); }

int m;
ll a[mxM * 2], b[mxM * 2], l;

signed main()
{
	IO_OP;

	cin >> m >> l;
	ll tot = 0, ans = 0;
	for(int i = -m; i <= m; i++) {
		cin >> a[i + m];
		tot += a[i + m] * i;
	}
	if(tot < l) {
		tot = -tot;
		l = -l;
		for(int i = 0; i < m; i++)
			swap(a[i], a[2 * m - i]);
	}
	tot = 0;
	for(int i = -m; i <= 0; i++) {
		tot += a[i + m] * i;
		b[i + m] = a[i + m];
		ans += b[i + m];
	}

	if(tot > l) {
		cout << "impossible\n";
		return 0;
	}
	for(int i = 1; i <= m; i++) {
		assert(tot <= l);
		b[i + m] = min((l - tot) / i, a[i + m]);
		tot += b[i + m] * i;
		ans += b[i + m];
	}
	assert(tot <= l);
	assert(tot + mxM >= l);

	int C = mxM * mxM * 2;
	vi dp(C * 2, -INF);
	dp[0 + C] = 0;

	for(int i = -m; i <= m; i++) {
		vi ndp(C * 2, -INF);
		for(int delta = -2 * m; delta <= 2 * m; delta++) {
			if(b[i + m] + delta < 0 || b[i + m] + delta > a[i + m]) continue;
			for(int j = 0; j < C * 2; j++) if(0 <= j + delta * i && j + delta * i < C * 2) {
				cmax(ndp[j + delta * i], dp[j] + delta);
			}
		}
		swap(dp, ndp);
	}
	if(dp[l - tot + C] < -1e8) cout << "impossible\n";
	else cout << ans + dp[l - tot + C] << '\n';


}

# Verdict Execution time Memory Grader output
1 Correct 10 ms 3156 KB Output is correct
2 Correct 14 ms 3156 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 38 ms 3156 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1234 ms 3192 KB Output is correct
7 Correct 526 ms 3180 KB Output is correct
8 Correct 1158 ms 3188 KB Output is correct
9 Correct 2084 ms 3176 KB Output is correct
10 Correct 135 ms 3192 KB Output is correct
11 Correct 122 ms 3188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3156 KB Output is correct
2 Correct 14 ms 3156 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 38 ms 3156 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1234 ms 3192 KB Output is correct
7 Correct 526 ms 3180 KB Output is correct
8 Correct 1158 ms 3188 KB Output is correct
9 Correct 2084 ms 3176 KB Output is correct
10 Correct 135 ms 3192 KB Output is correct
11 Correct 122 ms 3188 KB Output is correct
12 Correct 10 ms 3156 KB Output is correct
13 Correct 9 ms 3156 KB Output is correct
14 Correct 5 ms 3156 KB Output is correct
15 Correct 39 ms 3156 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1189 ms 3216 KB Output is correct
18 Correct 481 ms 3180 KB Output is correct
19 Correct 1109 ms 3180 KB Output is correct
20 Correct 2169 ms 3180 KB Output is correct
21 Correct 97 ms 3188 KB Output is correct
22 Correct 90 ms 3156 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 4340 ms 3188 KB Output is correct
25 Correct 1515 ms 3180 KB Output is correct
26 Execution timed out 5072 ms 3180 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3180 KB Output is correct
2 Correct 475 ms 3180 KB Output is correct
3 Correct 177 ms 3208 KB Output is correct
4 Correct 584 ms 3184 KB Output is correct
5 Correct 694 ms 3184 KB Output is correct
6 Correct 392 ms 3184 KB Output is correct
7 Correct 175 ms 3180 KB Output is correct
8 Correct 144 ms 3156 KB Output is correct
9 Correct 273 ms 3184 KB Output is correct
10 Correct 339 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3180 KB Output is correct
2 Correct 475 ms 3180 KB Output is correct
3 Correct 177 ms 3208 KB Output is correct
4 Correct 584 ms 3184 KB Output is correct
5 Correct 694 ms 3184 KB Output is correct
6 Correct 392 ms 3184 KB Output is correct
7 Correct 175 ms 3180 KB Output is correct
8 Correct 144 ms 3156 KB Output is correct
9 Correct 273 ms 3184 KB Output is correct
10 Correct 339 ms 3180 KB Output is correct
11 Correct 13 ms 3192 KB Output is correct
12 Correct 13 ms 3196 KB Output is correct
13 Correct 8 ms 3156 KB Output is correct
14 Correct 62 ms 3188 KB Output is correct
15 Correct 494 ms 3184 KB Output is correct
16 Correct 173 ms 3180 KB Output is correct
17 Correct 668 ms 3184 KB Output is correct
18 Correct 574 ms 3180 KB Output is correct
19 Correct 308 ms 3176 KB Output is correct
20 Correct 128 ms 3156 KB Output is correct
21 Correct 120 ms 3156 KB Output is correct
22 Correct 193 ms 3176 KB Output is correct
23 Correct 337 ms 3192 KB Output is correct
24 Correct 1037 ms 3208 KB Output is correct
25 Correct 379 ms 3184 KB Output is correct
26 Correct 1028 ms 3180 KB Output is correct
27 Correct 724 ms 3180 KB Output is correct
28 Correct 944 ms 3188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3180 KB Output is correct
2 Correct 475 ms 3180 KB Output is correct
3 Correct 177 ms 3208 KB Output is correct
4 Correct 584 ms 3184 KB Output is correct
5 Correct 694 ms 3184 KB Output is correct
6 Correct 392 ms 3184 KB Output is correct
7 Correct 175 ms 3180 KB Output is correct
8 Correct 144 ms 3156 KB Output is correct
9 Correct 273 ms 3184 KB Output is correct
10 Correct 339 ms 3180 KB Output is correct
11 Correct 51 ms 3184 KB Output is correct
12 Correct 452 ms 3188 KB Output is correct
13 Correct 171 ms 3156 KB Output is correct
14 Correct 572 ms 3184 KB Output is correct
15 Correct 537 ms 3180 KB Output is correct
16 Correct 364 ms 3184 KB Output is correct
17 Correct 119 ms 3184 KB Output is correct
18 Correct 116 ms 3180 KB Output is correct
19 Correct 223 ms 3176 KB Output is correct
20 Correct 331 ms 3180 KB Output is correct
21 Correct 101 ms 3156 KB Output is correct
22 Correct 98 ms 3184 KB Output is correct
23 Correct 1042 ms 3184 KB Output is correct
24 Correct 696 ms 3184 KB Output is correct
25 Correct 1168 ms 3176 KB Output is correct
26 Correct 1660 ms 3176 KB Output is correct
27 Correct 1191 ms 3180 KB Output is correct
28 Correct 1091 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3156 KB Output is correct
2 Correct 14 ms 3156 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 38 ms 3156 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1234 ms 3192 KB Output is correct
7 Correct 526 ms 3180 KB Output is correct
8 Correct 1158 ms 3188 KB Output is correct
9 Correct 2084 ms 3176 KB Output is correct
10 Correct 135 ms 3192 KB Output is correct
11 Correct 122 ms 3188 KB Output is correct
12 Correct 52 ms 3180 KB Output is correct
13 Correct 475 ms 3180 KB Output is correct
14 Correct 177 ms 3208 KB Output is correct
15 Correct 584 ms 3184 KB Output is correct
16 Correct 694 ms 3184 KB Output is correct
17 Correct 392 ms 3184 KB Output is correct
18 Correct 175 ms 3180 KB Output is correct
19 Correct 144 ms 3156 KB Output is correct
20 Correct 273 ms 3184 KB Output is correct
21 Correct 339 ms 3180 KB Output is correct
22 Correct 13 ms 3192 KB Output is correct
23 Correct 13 ms 3196 KB Output is correct
24 Correct 8 ms 3156 KB Output is correct
25 Correct 62 ms 3188 KB Output is correct
26 Correct 494 ms 3184 KB Output is correct
27 Correct 173 ms 3180 KB Output is correct
28 Correct 668 ms 3184 KB Output is correct
29 Correct 574 ms 3180 KB Output is correct
30 Correct 308 ms 3176 KB Output is correct
31 Correct 128 ms 3156 KB Output is correct
32 Correct 120 ms 3156 KB Output is correct
33 Correct 193 ms 3176 KB Output is correct
34 Correct 337 ms 3192 KB Output is correct
35 Correct 1037 ms 3208 KB Output is correct
36 Correct 379 ms 3184 KB Output is correct
37 Correct 1028 ms 3180 KB Output is correct
38 Correct 724 ms 3180 KB Output is correct
39 Correct 944 ms 3188 KB Output is correct
40 Correct 51 ms 3184 KB Output is correct
41 Correct 452 ms 3188 KB Output is correct
42 Correct 171 ms 3156 KB Output is correct
43 Correct 572 ms 3184 KB Output is correct
44 Correct 537 ms 3180 KB Output is correct
45 Correct 364 ms 3184 KB Output is correct
46 Correct 119 ms 3184 KB Output is correct
47 Correct 116 ms 3180 KB Output is correct
48 Correct 223 ms 3176 KB Output is correct
49 Correct 331 ms 3180 KB Output is correct
50 Correct 101 ms 3156 KB Output is correct
51 Correct 98 ms 3184 KB Output is correct
52 Correct 1042 ms 3184 KB Output is correct
53 Correct 696 ms 3184 KB Output is correct
54 Correct 1168 ms 3176 KB Output is correct
55 Correct 1660 ms 3176 KB Output is correct
56 Correct 1191 ms 3180 KB Output is correct
57 Correct 1091 ms 3180 KB Output is correct
58 Correct 10 ms 3156 KB Output is correct
59 Correct 14 ms 3156 KB Output is correct
60 Correct 6 ms 3156 KB Output is correct
61 Correct 42 ms 3156 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1149 ms 3196 KB Output is correct
64 Correct 483 ms 3180 KB Output is correct
65 Correct 1103 ms 3192 KB Output is correct
66 Correct 2070 ms 3184 KB Output is correct
67 Correct 100 ms 3156 KB Output is correct
68 Correct 95 ms 3176 KB Output is correct
69 Correct 483 ms 3180 KB Output is correct
70 Correct 151 ms 3180 KB Output is correct
71 Correct 535 ms 3184 KB Output is correct
72 Correct 527 ms 3180 KB Output is correct
73 Correct 361 ms 3156 KB Output is correct
74 Correct 115 ms 3180 KB Output is correct
75 Correct 94 ms 3184 KB Output is correct
76 Correct 194 ms 3180 KB Output is correct
77 Correct 328 ms 3256 KB Output is correct
78 Correct 953 ms 3200 KB Output is correct
79 Correct 359 ms 3180 KB Output is correct
80 Correct 1049 ms 3188 KB Output is correct
81 Correct 765 ms 3180 KB Output is correct
82 Correct 938 ms 3176 KB Output is correct
83 Correct 1094 ms 3184 KB Output is correct
84 Correct 635 ms 3180 KB Output is correct
85 Correct 1095 ms 3180 KB Output is correct
86 Correct 1565 ms 3184 KB Output is correct
87 Correct 1228 ms 3180 KB Output is correct
88 Correct 1110 ms 3176 KB Output is correct
89 Correct 1988 ms 3216 KB Output is correct
90 Correct 2819 ms 3216 KB Output is correct
91 Correct 2021 ms 3196 KB Output is correct
92 Correct 2365 ms 3272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3180 KB Output is correct
2 Correct 475 ms 3180 KB Output is correct
3 Correct 177 ms 3208 KB Output is correct
4 Correct 584 ms 3184 KB Output is correct
5 Correct 694 ms 3184 KB Output is correct
6 Correct 392 ms 3184 KB Output is correct
7 Correct 175 ms 3180 KB Output is correct
8 Correct 144 ms 3156 KB Output is correct
9 Correct 273 ms 3184 KB Output is correct
10 Correct 339 ms 3180 KB Output is correct
11 Correct 51 ms 3184 KB Output is correct
12 Correct 452 ms 3188 KB Output is correct
13 Correct 171 ms 3156 KB Output is correct
14 Correct 572 ms 3184 KB Output is correct
15 Correct 537 ms 3180 KB Output is correct
16 Correct 364 ms 3184 KB Output is correct
17 Correct 119 ms 3184 KB Output is correct
18 Correct 116 ms 3180 KB Output is correct
19 Correct 223 ms 3176 KB Output is correct
20 Correct 331 ms 3180 KB Output is correct
21 Correct 101 ms 3156 KB Output is correct
22 Correct 98 ms 3184 KB Output is correct
23 Correct 1042 ms 3184 KB Output is correct
24 Correct 696 ms 3184 KB Output is correct
25 Correct 1168 ms 3176 KB Output is correct
26 Correct 1660 ms 3176 KB Output is correct
27 Correct 1191 ms 3180 KB Output is correct
28 Correct 1091 ms 3180 KB Output is correct
29 Correct 39 ms 3180 KB Output is correct
30 Correct 487 ms 3180 KB Output is correct
31 Correct 164 ms 3156 KB Output is correct
32 Correct 543 ms 3176 KB Output is correct
33 Correct 562 ms 3184 KB Output is correct
34 Correct 351 ms 3180 KB Output is correct
35 Correct 110 ms 3156 KB Output is correct
36 Correct 89 ms 3180 KB Output is correct
37 Correct 182 ms 3180 KB Output is correct
38 Correct 348 ms 3184 KB Output is correct
39 Correct 110 ms 3176 KB Output is correct
40 Correct 90 ms 3180 KB Output is correct
41 Correct 981 ms 3184 KB Output is correct
42 Correct 671 ms 3180 KB Output is correct
43 Correct 1199 ms 3180 KB Output is correct
44 Correct 1632 ms 3180 KB Output is correct
45 Correct 1393 ms 3180 KB Output is correct
46 Correct 1232 ms 3184 KB Output is correct
47 Correct 258 ms 3156 KB Output is correct
48 Correct 235 ms 3184 KB Output is correct
49 Correct 4483 ms 3284 KB Output is correct
50 Correct 1863 ms 3180 KB Output is correct
51 Execution timed out 5098 ms 3156 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3156 KB Output is correct
2 Correct 14 ms 3156 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 38 ms 3156 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1234 ms 3192 KB Output is correct
7 Correct 526 ms 3180 KB Output is correct
8 Correct 1158 ms 3188 KB Output is correct
9 Correct 2084 ms 3176 KB Output is correct
10 Correct 135 ms 3192 KB Output is correct
11 Correct 122 ms 3188 KB Output is correct
12 Correct 10 ms 3156 KB Output is correct
13 Correct 9 ms 3156 KB Output is correct
14 Correct 5 ms 3156 KB Output is correct
15 Correct 39 ms 3156 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1189 ms 3216 KB Output is correct
18 Correct 481 ms 3180 KB Output is correct
19 Correct 1109 ms 3180 KB Output is correct
20 Correct 2169 ms 3180 KB Output is correct
21 Correct 97 ms 3188 KB Output is correct
22 Correct 90 ms 3156 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 4340 ms 3188 KB Output is correct
25 Correct 1515 ms 3180 KB Output is correct
26 Execution timed out 5072 ms 3180 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3180 KB Output is correct
2 Correct 475 ms 3180 KB Output is correct
3 Correct 177 ms 3208 KB Output is correct
4 Correct 584 ms 3184 KB Output is correct
5 Correct 694 ms 3184 KB Output is correct
6 Correct 392 ms 3184 KB Output is correct
7 Correct 175 ms 3180 KB Output is correct
8 Correct 144 ms 3156 KB Output is correct
9 Correct 273 ms 3184 KB Output is correct
10 Correct 339 ms 3180 KB Output is correct
11 Correct 51 ms 3184 KB Output is correct
12 Correct 452 ms 3188 KB Output is correct
13 Correct 171 ms 3156 KB Output is correct
14 Correct 572 ms 3184 KB Output is correct
15 Correct 537 ms 3180 KB Output is correct
16 Correct 364 ms 3184 KB Output is correct
17 Correct 119 ms 3184 KB Output is correct
18 Correct 116 ms 3180 KB Output is correct
19 Correct 223 ms 3176 KB Output is correct
20 Correct 331 ms 3180 KB Output is correct
21 Correct 101 ms 3156 KB Output is correct
22 Correct 98 ms 3184 KB Output is correct
23 Correct 1042 ms 3184 KB Output is correct
24 Correct 696 ms 3184 KB Output is correct
25 Correct 1168 ms 3176 KB Output is correct
26 Correct 1660 ms 3176 KB Output is correct
27 Correct 1191 ms 3180 KB Output is correct
28 Correct 1091 ms 3180 KB Output is correct
29 Correct 39 ms 3180 KB Output is correct
30 Correct 487 ms 3180 KB Output is correct
31 Correct 164 ms 3156 KB Output is correct
32 Correct 543 ms 3176 KB Output is correct
33 Correct 562 ms 3184 KB Output is correct
34 Correct 351 ms 3180 KB Output is correct
35 Correct 110 ms 3156 KB Output is correct
36 Correct 89 ms 3180 KB Output is correct
37 Correct 182 ms 3180 KB Output is correct
38 Correct 348 ms 3184 KB Output is correct
39 Correct 110 ms 3176 KB Output is correct
40 Correct 90 ms 3180 KB Output is correct
41 Correct 981 ms 3184 KB Output is correct
42 Correct 671 ms 3180 KB Output is correct
43 Correct 1199 ms 3180 KB Output is correct
44 Correct 1632 ms 3180 KB Output is correct
45 Correct 1393 ms 3180 KB Output is correct
46 Correct 1232 ms 3184 KB Output is correct
47 Correct 258 ms 3156 KB Output is correct
48 Correct 235 ms 3184 KB Output is correct
49 Correct 4483 ms 3284 KB Output is correct
50 Correct 1863 ms 3180 KB Output is correct
51 Execution timed out 5098 ms 3156 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3156 KB Output is correct
2 Correct 14 ms 3156 KB Output is correct
3 Correct 6 ms 3156 KB Output is correct
4 Correct 38 ms 3156 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1234 ms 3192 KB Output is correct
7 Correct 526 ms 3180 KB Output is correct
8 Correct 1158 ms 3188 KB Output is correct
9 Correct 2084 ms 3176 KB Output is correct
10 Correct 135 ms 3192 KB Output is correct
11 Correct 122 ms 3188 KB Output is correct
12 Correct 10 ms 3156 KB Output is correct
13 Correct 9 ms 3156 KB Output is correct
14 Correct 5 ms 3156 KB Output is correct
15 Correct 39 ms 3156 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1189 ms 3216 KB Output is correct
18 Correct 481 ms 3180 KB Output is correct
19 Correct 1109 ms 3180 KB Output is correct
20 Correct 2169 ms 3180 KB Output is correct
21 Correct 97 ms 3188 KB Output is correct
22 Correct 90 ms 3156 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 4340 ms 3188 KB Output is correct
25 Correct 1515 ms 3180 KB Output is correct
26 Execution timed out 5072 ms 3180 KB Time limit exceeded
27 Halted 0 ms 0 KB -