#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 = 55;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
2888 KB |
Output is correct |
3 |
Correct |
3 ms |
2900 KB |
Output is correct |
4 |
Correct |
10 ms |
2900 KB |
Output is correct |
5 |
Correct |
139 ms |
2908 KB |
Output is correct |
6 |
Correct |
157 ms |
2912 KB |
Output is correct |
7 |
Correct |
54 ms |
2900 KB |
Output is correct |
8 |
Correct |
129 ms |
2904 KB |
Output is correct |
9 |
Correct |
410 ms |
2920 KB |
Output is correct |
10 |
Correct |
29 ms |
2900 KB |
Output is correct |
11 |
Correct |
31 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
2888 KB |
Output is correct |
3 |
Correct |
3 ms |
2900 KB |
Output is correct |
4 |
Correct |
10 ms |
2900 KB |
Output is correct |
5 |
Correct |
139 ms |
2908 KB |
Output is correct |
6 |
Correct |
157 ms |
2912 KB |
Output is correct |
7 |
Correct |
54 ms |
2900 KB |
Output is correct |
8 |
Correct |
129 ms |
2904 KB |
Output is correct |
9 |
Correct |
410 ms |
2920 KB |
Output is correct |
10 |
Correct |
29 ms |
2900 KB |
Output is correct |
11 |
Correct |
31 ms |
2900 KB |
Output is correct |
12 |
Correct |
4 ms |
2900 KB |
Output is correct |
13 |
Correct |
6 ms |
2928 KB |
Output is correct |
14 |
Correct |
5 ms |
2900 KB |
Output is correct |
15 |
Correct |
12 ms |
2900 KB |
Output is correct |
16 |
Correct |
138 ms |
2900 KB |
Output is correct |
17 |
Correct |
154 ms |
2912 KB |
Output is correct |
18 |
Correct |
65 ms |
2900 KB |
Output is correct |
19 |
Correct |
126 ms |
2900 KB |
Output is correct |
20 |
Correct |
390 ms |
2908 KB |
Output is correct |
21 |
Correct |
29 ms |
2900 KB |
Output is correct |
22 |
Correct |
38 ms |
2908 KB |
Output is correct |
23 |
Correct |
2258 ms |
2908 KB |
Output is correct |
24 |
Incorrect |
2337 ms |
2912 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2900 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
2892 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2900 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
2892 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2900 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
2892 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
2888 KB |
Output is correct |
3 |
Correct |
3 ms |
2900 KB |
Output is correct |
4 |
Correct |
10 ms |
2900 KB |
Output is correct |
5 |
Correct |
139 ms |
2908 KB |
Output is correct |
6 |
Correct |
157 ms |
2912 KB |
Output is correct |
7 |
Correct |
54 ms |
2900 KB |
Output is correct |
8 |
Correct |
129 ms |
2904 KB |
Output is correct |
9 |
Correct |
410 ms |
2920 KB |
Output is correct |
10 |
Correct |
29 ms |
2900 KB |
Output is correct |
11 |
Correct |
31 ms |
2900 KB |
Output is correct |
12 |
Correct |
8 ms |
2900 KB |
Output is correct |
13 |
Execution timed out |
5061 ms |
2892 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2900 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
2892 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
2888 KB |
Output is correct |
3 |
Correct |
3 ms |
2900 KB |
Output is correct |
4 |
Correct |
10 ms |
2900 KB |
Output is correct |
5 |
Correct |
139 ms |
2908 KB |
Output is correct |
6 |
Correct |
157 ms |
2912 KB |
Output is correct |
7 |
Correct |
54 ms |
2900 KB |
Output is correct |
8 |
Correct |
129 ms |
2904 KB |
Output is correct |
9 |
Correct |
410 ms |
2920 KB |
Output is correct |
10 |
Correct |
29 ms |
2900 KB |
Output is correct |
11 |
Correct |
31 ms |
2900 KB |
Output is correct |
12 |
Correct |
4 ms |
2900 KB |
Output is correct |
13 |
Correct |
6 ms |
2928 KB |
Output is correct |
14 |
Correct |
5 ms |
2900 KB |
Output is correct |
15 |
Correct |
12 ms |
2900 KB |
Output is correct |
16 |
Correct |
138 ms |
2900 KB |
Output is correct |
17 |
Correct |
154 ms |
2912 KB |
Output is correct |
18 |
Correct |
65 ms |
2900 KB |
Output is correct |
19 |
Correct |
126 ms |
2900 KB |
Output is correct |
20 |
Correct |
390 ms |
2908 KB |
Output is correct |
21 |
Correct |
29 ms |
2900 KB |
Output is correct |
22 |
Correct |
38 ms |
2908 KB |
Output is correct |
23 |
Correct |
2258 ms |
2908 KB |
Output is correct |
24 |
Incorrect |
2337 ms |
2912 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2900 KB |
Output is correct |
2 |
Execution timed out |
5061 ms |
2892 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
2888 KB |
Output is correct |
3 |
Correct |
3 ms |
2900 KB |
Output is correct |
4 |
Correct |
10 ms |
2900 KB |
Output is correct |
5 |
Correct |
139 ms |
2908 KB |
Output is correct |
6 |
Correct |
157 ms |
2912 KB |
Output is correct |
7 |
Correct |
54 ms |
2900 KB |
Output is correct |
8 |
Correct |
129 ms |
2904 KB |
Output is correct |
9 |
Correct |
410 ms |
2920 KB |
Output is correct |
10 |
Correct |
29 ms |
2900 KB |
Output is correct |
11 |
Correct |
31 ms |
2900 KB |
Output is correct |
12 |
Correct |
4 ms |
2900 KB |
Output is correct |
13 |
Correct |
6 ms |
2928 KB |
Output is correct |
14 |
Correct |
5 ms |
2900 KB |
Output is correct |
15 |
Correct |
12 ms |
2900 KB |
Output is correct |
16 |
Correct |
138 ms |
2900 KB |
Output is correct |
17 |
Correct |
154 ms |
2912 KB |
Output is correct |
18 |
Correct |
65 ms |
2900 KB |
Output is correct |
19 |
Correct |
126 ms |
2900 KB |
Output is correct |
20 |
Correct |
390 ms |
2908 KB |
Output is correct |
21 |
Correct |
29 ms |
2900 KB |
Output is correct |
22 |
Correct |
38 ms |
2908 KB |
Output is correct |
23 |
Correct |
2258 ms |
2908 KB |
Output is correct |
24 |
Incorrect |
2337 ms |
2912 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |