#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 200;
ll const inf = 2000000000;
ll v[5 + nmax], t[5 + nmax];
ll dp[5 + 2 * nmax][5 + 2 * nmax][5 + nmax][2];
int n;
ll extract(int x, int y, int val, int h){
if(val < 0)
return inf;
else
return dp[x][y][val][h];
}
ll dist(int x, int y){
return fabs(v[x] - v[y]);
}
void update(ll &number, ll val){
number = min(number, val);
}
int main()
{
int l;
cin >> n >> l;
for(int i = 1;i <= n; i++)
cin >> v[i];
for(int i = 1;i <= n; i++)
cin >> t[i];
for(int i = 1;i <= n; i++) {
v[n + i] = v[i] + l;
t[n + i] = t[i];
}
for(int i = 0;i <= nmax * 2; i++)
for(int j = 0; j <= nmax * 2; j++)
for(int h = 0; h <= nmax; h++)
dp[i][j][h][0] = dp[i][j][h][1] = inf;
dp[n][n][(abs(l - v[n]) <= t[n])][0] = fabs(l - v[n]);
dp[n + 1][n + 1][(abs(l - v[n + 1]) <= t[n + 1])][0] = fabs(l - v[n + 1]);
int result = 0;
for(int dif = 0; dif < n; dif++)
for(int i = 1;i <= 2 * n; i++){
int j = i + dif;
if(j <= 2 * n){
for(int k = 0; k <= dif + 1; k++){
ll time = dp[i][j][k][0] + dist(i - 1, i);
update(dp[i - 1][j][k + (time <= t[i - 1])][0], time);
time = dp[i][j][k][1] + dist(i - 1, j);
update(dp[i - 1][j][k + (time <= t[i - 1])][0], time);
time = dp[i][j][k][0] + dist(j + 1, i);
update(dp[i][j + 1][k + (time <= t[j + 1])][1], time);
time = dp[i][j][k][1] + dist(j + 1, j);
update(dp[i][j + 1][k + (time <= t[j + 1])][1], time);
if(dp[i][j][k][0] <= inf - 5 || dp[i][j][k][1] <= inf - 5)
result = max(result, k);
}
}
}
cout << result;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
518048 KB |
Output is correct |
2 |
Correct |
248 ms |
518136 KB |
Output is correct |
3 |
Correct |
243 ms |
518008 KB |
Output is correct |
4 |
Correct |
248 ms |
518008 KB |
Output is correct |
5 |
Correct |
244 ms |
518008 KB |
Output is correct |
6 |
Correct |
241 ms |
518008 KB |
Output is correct |
7 |
Correct |
249 ms |
518012 KB |
Output is correct |
8 |
Correct |
243 ms |
518008 KB |
Output is correct |
9 |
Correct |
247 ms |
518008 KB |
Output is correct |
10 |
Correct |
250 ms |
518008 KB |
Output is correct |
11 |
Correct |
246 ms |
518008 KB |
Output is correct |
12 |
Correct |
240 ms |
518016 KB |
Output is correct |
13 |
Correct |
243 ms |
518012 KB |
Output is correct |
14 |
Correct |
246 ms |
518008 KB |
Output is correct |
15 |
Correct |
244 ms |
518008 KB |
Output is correct |
16 |
Correct |
242 ms |
518012 KB |
Output is correct |
17 |
Correct |
244 ms |
518008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
518048 KB |
Output is correct |
2 |
Correct |
248 ms |
518136 KB |
Output is correct |
3 |
Correct |
243 ms |
518008 KB |
Output is correct |
4 |
Correct |
248 ms |
518008 KB |
Output is correct |
5 |
Correct |
244 ms |
518008 KB |
Output is correct |
6 |
Correct |
241 ms |
518008 KB |
Output is correct |
7 |
Correct |
249 ms |
518012 KB |
Output is correct |
8 |
Correct |
243 ms |
518008 KB |
Output is correct |
9 |
Correct |
247 ms |
518008 KB |
Output is correct |
10 |
Correct |
250 ms |
518008 KB |
Output is correct |
11 |
Correct |
246 ms |
518008 KB |
Output is correct |
12 |
Correct |
240 ms |
518016 KB |
Output is correct |
13 |
Correct |
243 ms |
518012 KB |
Output is correct |
14 |
Correct |
246 ms |
518008 KB |
Output is correct |
15 |
Correct |
244 ms |
518008 KB |
Output is correct |
16 |
Correct |
242 ms |
518012 KB |
Output is correct |
17 |
Correct |
244 ms |
518008 KB |
Output is correct |
18 |
Correct |
253 ms |
517968 KB |
Output is correct |
19 |
Correct |
246 ms |
518008 KB |
Output is correct |
20 |
Correct |
242 ms |
518008 KB |
Output is correct |
21 |
Correct |
247 ms |
518076 KB |
Output is correct |
22 |
Correct |
245 ms |
518008 KB |
Output is correct |
23 |
Correct |
242 ms |
518008 KB |
Output is correct |
24 |
Correct |
242 ms |
518008 KB |
Output is correct |
25 |
Correct |
240 ms |
518012 KB |
Output is correct |
26 |
Correct |
246 ms |
518008 KB |
Output is correct |
27 |
Correct |
252 ms |
518008 KB |
Output is correct |
28 |
Correct |
242 ms |
518008 KB |
Output is correct |
29 |
Correct |
245 ms |
518008 KB |
Output is correct |
30 |
Correct |
250 ms |
518008 KB |
Output is correct |
31 |
Correct |
249 ms |
518008 KB |
Output is correct |
32 |
Correct |
249 ms |
518008 KB |
Output is correct |
33 |
Correct |
242 ms |
518008 KB |
Output is correct |
34 |
Correct |
246 ms |
518008 KB |
Output is correct |
35 |
Correct |
246 ms |
518008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
518048 KB |
Output is correct |
2 |
Correct |
248 ms |
518136 KB |
Output is correct |
3 |
Correct |
243 ms |
518008 KB |
Output is correct |
4 |
Correct |
248 ms |
518008 KB |
Output is correct |
5 |
Correct |
244 ms |
518008 KB |
Output is correct |
6 |
Correct |
241 ms |
518008 KB |
Output is correct |
7 |
Correct |
249 ms |
518012 KB |
Output is correct |
8 |
Correct |
243 ms |
518008 KB |
Output is correct |
9 |
Correct |
247 ms |
518008 KB |
Output is correct |
10 |
Correct |
250 ms |
518008 KB |
Output is correct |
11 |
Correct |
246 ms |
518008 KB |
Output is correct |
12 |
Correct |
240 ms |
518016 KB |
Output is correct |
13 |
Correct |
243 ms |
518012 KB |
Output is correct |
14 |
Correct |
246 ms |
518008 KB |
Output is correct |
15 |
Correct |
244 ms |
518008 KB |
Output is correct |
16 |
Correct |
242 ms |
518012 KB |
Output is correct |
17 |
Correct |
244 ms |
518008 KB |
Output is correct |
18 |
Runtime error |
1087 ms |
978700 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
338 ms |
518048 KB |
Output is correct |
2 |
Correct |
248 ms |
518136 KB |
Output is correct |
3 |
Correct |
243 ms |
518008 KB |
Output is correct |
4 |
Correct |
248 ms |
518008 KB |
Output is correct |
5 |
Correct |
244 ms |
518008 KB |
Output is correct |
6 |
Correct |
241 ms |
518008 KB |
Output is correct |
7 |
Correct |
249 ms |
518012 KB |
Output is correct |
8 |
Correct |
243 ms |
518008 KB |
Output is correct |
9 |
Correct |
247 ms |
518008 KB |
Output is correct |
10 |
Correct |
250 ms |
518008 KB |
Output is correct |
11 |
Correct |
246 ms |
518008 KB |
Output is correct |
12 |
Correct |
240 ms |
518016 KB |
Output is correct |
13 |
Correct |
243 ms |
518012 KB |
Output is correct |
14 |
Correct |
246 ms |
518008 KB |
Output is correct |
15 |
Correct |
244 ms |
518008 KB |
Output is correct |
16 |
Correct |
242 ms |
518012 KB |
Output is correct |
17 |
Correct |
244 ms |
518008 KB |
Output is correct |
18 |
Correct |
253 ms |
517968 KB |
Output is correct |
19 |
Correct |
246 ms |
518008 KB |
Output is correct |
20 |
Correct |
242 ms |
518008 KB |
Output is correct |
21 |
Correct |
247 ms |
518076 KB |
Output is correct |
22 |
Correct |
245 ms |
518008 KB |
Output is correct |
23 |
Correct |
242 ms |
518008 KB |
Output is correct |
24 |
Correct |
242 ms |
518008 KB |
Output is correct |
25 |
Correct |
240 ms |
518012 KB |
Output is correct |
26 |
Correct |
246 ms |
518008 KB |
Output is correct |
27 |
Correct |
252 ms |
518008 KB |
Output is correct |
28 |
Correct |
242 ms |
518008 KB |
Output is correct |
29 |
Correct |
245 ms |
518008 KB |
Output is correct |
30 |
Correct |
250 ms |
518008 KB |
Output is correct |
31 |
Correct |
249 ms |
518008 KB |
Output is correct |
32 |
Correct |
249 ms |
518008 KB |
Output is correct |
33 |
Correct |
242 ms |
518008 KB |
Output is correct |
34 |
Correct |
246 ms |
518008 KB |
Output is correct |
35 |
Correct |
246 ms |
518008 KB |
Output is correct |
36 |
Runtime error |
1087 ms |
978700 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
37 |
Halted |
0 ms |
0 KB |
- |