#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1100000;
int dp[N], nx[N];
void solve() {
int m;
ll x;
cin >> m >> x;
ll mins = 0, maxs = 0;
vector<pii> v;
for (int i = -m; i <= m; ++i) {
int f;
cin >> f;
if (i < 0) mins += f * i;
else maxs += f * i;
int z = 1;
while (f > z) {
v.push_back({z * i, z});
f -= z;
z *= 2;
}
if (f > 0) v.push_back({f * i, f});
}
memset(dp, 0xc0, sizeof dp);
memset(nx, 0xc0, sizeof nx);
dp[0] = nx[0] = 0;
for (pii p : v) {
for (int i = -550000; i <= 550000; ++i) {
int j = i + p.first;
if (-550000 <= j && j <= 550000) nx[(j + N) % N] = max(nx[(j + N) % N], dp[(i + N) % N] + p.second);
}
copy(nx, nx+N, dp);
}
if (x < mins || x > maxs) cout << "impossible\n";
else cout << (dp[(x + N) % N] < 0 ? "impossible" : to_string(dp[(x + N) % N])) << '\n';
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
9048 KB |
Output is correct |
2 |
Correct |
21 ms |
9064 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
81 ms |
9052 KB |
Output is correct |
5 |
Correct |
1288 ms |
9300 KB |
Output is correct |
6 |
Correct |
1356 ms |
9052 KB |
Output is correct |
7 |
Correct |
545 ms |
9048 KB |
Output is correct |
8 |
Correct |
1342 ms |
9056 KB |
Output is correct |
9 |
Correct |
1609 ms |
9072 KB |
Output is correct |
10 |
Correct |
46 ms |
9052 KB |
Output is correct |
11 |
Correct |
47 ms |
9048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
9048 KB |
Output is correct |
2 |
Correct |
21 ms |
9064 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
81 ms |
9052 KB |
Output is correct |
5 |
Correct |
1288 ms |
9300 KB |
Output is correct |
6 |
Correct |
1356 ms |
9052 KB |
Output is correct |
7 |
Correct |
545 ms |
9048 KB |
Output is correct |
8 |
Correct |
1342 ms |
9056 KB |
Output is correct |
9 |
Correct |
1609 ms |
9072 KB |
Output is correct |
10 |
Correct |
46 ms |
9052 KB |
Output is correct |
11 |
Correct |
47 ms |
9048 KB |
Output is correct |
12 |
Correct |
25 ms |
9052 KB |
Output is correct |
13 |
Correct |
20 ms |
9264 KB |
Output is correct |
14 |
Correct |
9 ms |
9052 KB |
Output is correct |
15 |
Correct |
81 ms |
9052 KB |
Output is correct |
16 |
Correct |
1316 ms |
9312 KB |
Output is correct |
17 |
Correct |
1366 ms |
9056 KB |
Output is correct |
18 |
Correct |
563 ms |
9300 KB |
Output is correct |
19 |
Correct |
1323 ms |
9052 KB |
Output is correct |
20 |
Correct |
1601 ms |
9064 KB |
Output is correct |
21 |
Correct |
47 ms |
9052 KB |
Output is correct |
22 |
Correct |
47 ms |
9052 KB |
Output is correct |
23 |
Correct |
3162 ms |
9072 KB |
Output is correct |
24 |
Correct |
3157 ms |
9068 KB |
Output is correct |
25 |
Correct |
1177 ms |
9296 KB |
Output is correct |
26 |
Correct |
3787 ms |
9076 KB |
Output is correct |
27 |
Correct |
3780 ms |
9080 KB |
Output is correct |
28 |
Correct |
58 ms |
9048 KB |
Output is correct |
29 |
Correct |
70 ms |
9048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
9048 KB |
Output is correct |
2 |
Correct |
21 ms |
9064 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
81 ms |
9052 KB |
Output is correct |
5 |
Correct |
1288 ms |
9300 KB |
Output is correct |
6 |
Correct |
1356 ms |
9052 KB |
Output is correct |
7 |
Correct |
545 ms |
9048 KB |
Output is correct |
8 |
Correct |
1342 ms |
9056 KB |
Output is correct |
9 |
Correct |
1609 ms |
9072 KB |
Output is correct |
10 |
Correct |
46 ms |
9052 KB |
Output is correct |
11 |
Correct |
47 ms |
9048 KB |
Output is correct |
12 |
Correct |
83 ms |
9052 KB |
Output is correct |
13 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
9048 KB |
Output is correct |
2 |
Correct |
21 ms |
9064 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
81 ms |
9052 KB |
Output is correct |
5 |
Correct |
1288 ms |
9300 KB |
Output is correct |
6 |
Correct |
1356 ms |
9052 KB |
Output is correct |
7 |
Correct |
545 ms |
9048 KB |
Output is correct |
8 |
Correct |
1342 ms |
9056 KB |
Output is correct |
9 |
Correct |
1609 ms |
9072 KB |
Output is correct |
10 |
Correct |
46 ms |
9052 KB |
Output is correct |
11 |
Correct |
47 ms |
9048 KB |
Output is correct |
12 |
Correct |
25 ms |
9052 KB |
Output is correct |
13 |
Correct |
20 ms |
9264 KB |
Output is correct |
14 |
Correct |
9 ms |
9052 KB |
Output is correct |
15 |
Correct |
81 ms |
9052 KB |
Output is correct |
16 |
Correct |
1316 ms |
9312 KB |
Output is correct |
17 |
Correct |
1366 ms |
9056 KB |
Output is correct |
18 |
Correct |
563 ms |
9300 KB |
Output is correct |
19 |
Correct |
1323 ms |
9052 KB |
Output is correct |
20 |
Correct |
1601 ms |
9064 KB |
Output is correct |
21 |
Correct |
47 ms |
9052 KB |
Output is correct |
22 |
Correct |
47 ms |
9052 KB |
Output is correct |
23 |
Correct |
3162 ms |
9072 KB |
Output is correct |
24 |
Correct |
3157 ms |
9068 KB |
Output is correct |
25 |
Correct |
1177 ms |
9296 KB |
Output is correct |
26 |
Correct |
3787 ms |
9076 KB |
Output is correct |
27 |
Correct |
3780 ms |
9080 KB |
Output is correct |
28 |
Correct |
58 ms |
9048 KB |
Output is correct |
29 |
Correct |
70 ms |
9048 KB |
Output is correct |
30 |
Correct |
83 ms |
9052 KB |
Output is correct |
31 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
9052 KB |
Output is correct |
2 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
9048 KB |
Output is correct |
2 |
Correct |
21 ms |
9064 KB |
Output is correct |
3 |
Correct |
9 ms |
9048 KB |
Output is correct |
4 |
Correct |
81 ms |
9052 KB |
Output is correct |
5 |
Correct |
1288 ms |
9300 KB |
Output is correct |
6 |
Correct |
1356 ms |
9052 KB |
Output is correct |
7 |
Correct |
545 ms |
9048 KB |
Output is correct |
8 |
Correct |
1342 ms |
9056 KB |
Output is correct |
9 |
Correct |
1609 ms |
9072 KB |
Output is correct |
10 |
Correct |
46 ms |
9052 KB |
Output is correct |
11 |
Correct |
47 ms |
9048 KB |
Output is correct |
12 |
Correct |
25 ms |
9052 KB |
Output is correct |
13 |
Correct |
20 ms |
9264 KB |
Output is correct |
14 |
Correct |
9 ms |
9052 KB |
Output is correct |
15 |
Correct |
81 ms |
9052 KB |
Output is correct |
16 |
Correct |
1316 ms |
9312 KB |
Output is correct |
17 |
Correct |
1366 ms |
9056 KB |
Output is correct |
18 |
Correct |
563 ms |
9300 KB |
Output is correct |
19 |
Correct |
1323 ms |
9052 KB |
Output is correct |
20 |
Correct |
1601 ms |
9064 KB |
Output is correct |
21 |
Correct |
47 ms |
9052 KB |
Output is correct |
22 |
Correct |
47 ms |
9052 KB |
Output is correct |
23 |
Correct |
3162 ms |
9072 KB |
Output is correct |
24 |
Correct |
3157 ms |
9068 KB |
Output is correct |
25 |
Correct |
1177 ms |
9296 KB |
Output is correct |
26 |
Correct |
3787 ms |
9076 KB |
Output is correct |
27 |
Correct |
3780 ms |
9080 KB |
Output is correct |
28 |
Correct |
58 ms |
9048 KB |
Output is correct |
29 |
Correct |
70 ms |
9048 KB |
Output is correct |
30 |
Correct |
83 ms |
9052 KB |
Output is correct |
31 |
Incorrect |
232 ms |
9052 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |