#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxm = 105;
const int maxi = maxm * maxm * maxm;
//const int maxi = 10;
const int inf = 1e9 + 5;
int pf[2][maxi * 2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m;
ll l;
cin >> m >> l;
m++;
vector<ll> ok(2 * m + 1, 0ll);
for (int i = -m + 1; i < m; i++)
{
cin >> ok[m + i];
}
fill(pf[0], pf[0] + maxi * 2, -inf);
fill(pf[1], pf[1] + maxi * 2, -inf);
pf[0][maxi] = 0;
int cur = 0;
for (int i = -m; i <= m; i++)
{
fill(pf[cur ^ 1], pf[cur ^ 1] + maxi * 2, -inf);
for (int j = -maxi; j < maxi; j++) if (pf[cur][maxi + j] != -inf)
{
int cnt = 0;
for (int d = j; cnt <= ok[m + i] && -maxi < d && d < maxi; d += i, cnt++)
{
pf[cur ^ 1][maxi + d] = max(pf[cur ^ 1][maxi + d], pf[cur][maxi + j] + cnt);
}
}
cur ^= 1;
}
if (abs(l) >= maxi || pf[cur][maxi + l] == -inf)
{
cout << "impossible\n";
}
else
{
cout << pf[cur][maxi + l] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18388 KB |
Output is correct |
2 |
Correct |
32 ms |
18332 KB |
Output is correct |
3 |
Correct |
21 ms |
18444 KB |
Output is correct |
4 |
Correct |
64 ms |
18388 KB |
Output is correct |
5 |
Correct |
383 ms |
18416 KB |
Output is correct |
6 |
Correct |
416 ms |
18416 KB |
Output is correct |
7 |
Correct |
277 ms |
18424 KB |
Output is correct |
8 |
Correct |
407 ms |
18416 KB |
Output is correct |
9 |
Correct |
619 ms |
18420 KB |
Output is correct |
10 |
Correct |
248 ms |
18388 KB |
Output is correct |
11 |
Correct |
272 ms |
18420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18388 KB |
Output is correct |
2 |
Correct |
32 ms |
18332 KB |
Output is correct |
3 |
Correct |
21 ms |
18444 KB |
Output is correct |
4 |
Correct |
64 ms |
18388 KB |
Output is correct |
5 |
Correct |
383 ms |
18416 KB |
Output is correct |
6 |
Correct |
416 ms |
18416 KB |
Output is correct |
7 |
Correct |
277 ms |
18424 KB |
Output is correct |
8 |
Correct |
407 ms |
18416 KB |
Output is correct |
9 |
Correct |
619 ms |
18420 KB |
Output is correct |
10 |
Correct |
248 ms |
18388 KB |
Output is correct |
11 |
Correct |
272 ms |
18420 KB |
Output is correct |
12 |
Correct |
32 ms |
18344 KB |
Output is correct |
13 |
Correct |
38 ms |
18436 KB |
Output is correct |
14 |
Correct |
34 ms |
18388 KB |
Output is correct |
15 |
Correct |
81 ms |
18420 KB |
Output is correct |
16 |
Correct |
395 ms |
18420 KB |
Output is correct |
17 |
Correct |
395 ms |
18424 KB |
Output is correct |
18 |
Correct |
294 ms |
18424 KB |
Output is correct |
19 |
Correct |
401 ms |
18428 KB |
Output is correct |
20 |
Correct |
628 ms |
18508 KB |
Output is correct |
21 |
Correct |
250 ms |
18388 KB |
Output is correct |
22 |
Correct |
253 ms |
18416 KB |
Output is correct |
23 |
Correct |
3462 ms |
18508 KB |
Output is correct |
24 |
Correct |
3448 ms |
18420 KB |
Output is correct |
25 |
Correct |
990 ms |
18388 KB |
Output is correct |
26 |
Execution timed out |
5069 ms |
18388 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
18388 KB |
Output is correct |
2 |
Execution timed out |
5052 ms |
18392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
18388 KB |
Output is correct |
2 |
Execution timed out |
5052 ms |
18392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
18388 KB |
Output is correct |
2 |
Execution timed out |
5052 ms |
18392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18388 KB |
Output is correct |
2 |
Correct |
32 ms |
18332 KB |
Output is correct |
3 |
Correct |
21 ms |
18444 KB |
Output is correct |
4 |
Correct |
64 ms |
18388 KB |
Output is correct |
5 |
Correct |
383 ms |
18416 KB |
Output is correct |
6 |
Correct |
416 ms |
18416 KB |
Output is correct |
7 |
Correct |
277 ms |
18424 KB |
Output is correct |
8 |
Correct |
407 ms |
18416 KB |
Output is correct |
9 |
Correct |
619 ms |
18420 KB |
Output is correct |
10 |
Correct |
248 ms |
18388 KB |
Output is correct |
11 |
Correct |
272 ms |
18420 KB |
Output is correct |
12 |
Correct |
62 ms |
18388 KB |
Output is correct |
13 |
Execution timed out |
5052 ms |
18392 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
18388 KB |
Output is correct |
2 |
Execution timed out |
5052 ms |
18392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18388 KB |
Output is correct |
2 |
Correct |
32 ms |
18332 KB |
Output is correct |
3 |
Correct |
21 ms |
18444 KB |
Output is correct |
4 |
Correct |
64 ms |
18388 KB |
Output is correct |
5 |
Correct |
383 ms |
18416 KB |
Output is correct |
6 |
Correct |
416 ms |
18416 KB |
Output is correct |
7 |
Correct |
277 ms |
18424 KB |
Output is correct |
8 |
Correct |
407 ms |
18416 KB |
Output is correct |
9 |
Correct |
619 ms |
18420 KB |
Output is correct |
10 |
Correct |
248 ms |
18388 KB |
Output is correct |
11 |
Correct |
272 ms |
18420 KB |
Output is correct |
12 |
Correct |
32 ms |
18344 KB |
Output is correct |
13 |
Correct |
38 ms |
18436 KB |
Output is correct |
14 |
Correct |
34 ms |
18388 KB |
Output is correct |
15 |
Correct |
81 ms |
18420 KB |
Output is correct |
16 |
Correct |
395 ms |
18420 KB |
Output is correct |
17 |
Correct |
395 ms |
18424 KB |
Output is correct |
18 |
Correct |
294 ms |
18424 KB |
Output is correct |
19 |
Correct |
401 ms |
18428 KB |
Output is correct |
20 |
Correct |
628 ms |
18508 KB |
Output is correct |
21 |
Correct |
250 ms |
18388 KB |
Output is correct |
22 |
Correct |
253 ms |
18416 KB |
Output is correct |
23 |
Correct |
3462 ms |
18508 KB |
Output is correct |
24 |
Correct |
3448 ms |
18420 KB |
Output is correct |
25 |
Correct |
990 ms |
18388 KB |
Output is correct |
26 |
Execution timed out |
5069 ms |
18388 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
18388 KB |
Output is correct |
2 |
Execution timed out |
5052 ms |
18392 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18388 KB |
Output is correct |
2 |
Correct |
32 ms |
18332 KB |
Output is correct |
3 |
Correct |
21 ms |
18444 KB |
Output is correct |
4 |
Correct |
64 ms |
18388 KB |
Output is correct |
5 |
Correct |
383 ms |
18416 KB |
Output is correct |
6 |
Correct |
416 ms |
18416 KB |
Output is correct |
7 |
Correct |
277 ms |
18424 KB |
Output is correct |
8 |
Correct |
407 ms |
18416 KB |
Output is correct |
9 |
Correct |
619 ms |
18420 KB |
Output is correct |
10 |
Correct |
248 ms |
18388 KB |
Output is correct |
11 |
Correct |
272 ms |
18420 KB |
Output is correct |
12 |
Correct |
32 ms |
18344 KB |
Output is correct |
13 |
Correct |
38 ms |
18436 KB |
Output is correct |
14 |
Correct |
34 ms |
18388 KB |
Output is correct |
15 |
Correct |
81 ms |
18420 KB |
Output is correct |
16 |
Correct |
395 ms |
18420 KB |
Output is correct |
17 |
Correct |
395 ms |
18424 KB |
Output is correct |
18 |
Correct |
294 ms |
18424 KB |
Output is correct |
19 |
Correct |
401 ms |
18428 KB |
Output is correct |
20 |
Correct |
628 ms |
18508 KB |
Output is correct |
21 |
Correct |
250 ms |
18388 KB |
Output is correct |
22 |
Correct |
253 ms |
18416 KB |
Output is correct |
23 |
Correct |
3462 ms |
18508 KB |
Output is correct |
24 |
Correct |
3448 ms |
18420 KB |
Output is correct |
25 |
Correct |
990 ms |
18388 KB |
Output is correct |
26 |
Execution timed out |
5069 ms |
18388 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |