#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const ll mod = 1e9 + 7;
const int mxn = 2e5 + 5, mxm = 1e5;
ll dp[2][205][205][205],n , L, x[205], t[205];
void ckmin(ll &a, ll b){
if(a > b)a = b;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> L;
forr(i, 1, n + 1)cin >> x[i];
forr(i, 1, n + 1)cin >> t[i];
x[n + 1] = L;
forr(i, 0, n + 2){
forr(j, 0, n + 2){
forr(k, 0, n + 2){
dp[0][i][j][k] = dp[1][i][j][k] = 1e16;
}
}
}
dp[0][0][n + 1][0] = dp[1][0][n + 1][0] = 0;
for(int l = 0; l < n; l++){
for(int r = n + 1; r >= l + 2; r--){
for(int take = 0; take <= n; take++){
ll tt = min(dp[0][l][r][take] + abs(x[l + 1] - x[l]), dp[1][l][r][take] + L - abs(x[r] - x[l + 1]));
ckmin(dp[0][l + 1][r][take + (tt <= t[l + 1])], tt);
tt = min(dp[0][l][r][take] + L - abs(x[l] - x[r - 1]), dp[1][l][r][take] + abs(x[r] - x[r - 1]));
ckmin(dp[1][l][r - 1][take + (tt <= t[r - 1])], tt);
}
}
}
int ans = 0;
for(int i = 0; i <= n + 1; i++){
for(int j = 0; j <= n + 1; j++){
for(int k = 0; k <= n; k++){
if(dp[0][i][j][k] < 1e16 || dp[1][i][j][k] < 1e16){
ans = max(ans, k);
}
}
}
}
cout << ans;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1364 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1232 KB |
Output is correct |
26 |
Correct |
1 ms |
1232 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
1364 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1364 KB |
Output is correct |
34 |
Correct |
1 ms |
1356 KB |
Output is correct |
35 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
73 ms |
106956 KB |
Output is correct |
19 |
Correct |
42 ms |
65100 KB |
Output is correct |
20 |
Correct |
22 ms |
35052 KB |
Output is correct |
21 |
Correct |
40 ms |
61580 KB |
Output is correct |
22 |
Correct |
53 ms |
79572 KB |
Output is correct |
23 |
Correct |
18 ms |
29964 KB |
Output is correct |
24 |
Correct |
14 ms |
23508 KB |
Output is correct |
25 |
Correct |
19 ms |
29268 KB |
Output is correct |
26 |
Correct |
7 ms |
11476 KB |
Output is correct |
27 |
Correct |
20 ms |
30548 KB |
Output is correct |
28 |
Correct |
16 ms |
21844 KB |
Output is correct |
29 |
Correct |
20 ms |
31224 KB |
Output is correct |
30 |
Correct |
15 ms |
24660 KB |
Output is correct |
31 |
Correct |
18 ms |
29264 KB |
Output is correct |
32 |
Correct |
9 ms |
15572 KB |
Output is correct |
33 |
Correct |
19 ms |
29268 KB |
Output is correct |
34 |
Correct |
6 ms |
10704 KB |
Output is correct |
35 |
Correct |
18 ms |
28624 KB |
Output is correct |
36 |
Correct |
8 ms |
13908 KB |
Output is correct |
37 |
Correct |
18 ms |
30516 KB |
Output is correct |
38 |
Correct |
10 ms |
16996 KB |
Output is correct |
39 |
Correct |
20 ms |
31864 KB |
Output is correct |
40 |
Correct |
13 ms |
18900 KB |
Output is correct |
41 |
Correct |
93 ms |
131660 KB |
Output is correct |
42 |
Correct |
56 ms |
88960 KB |
Output is correct |
43 |
Correct |
101 ms |
131568 KB |
Output is correct |
44 |
Correct |
53 ms |
87892 KB |
Output is correct |
45 |
Correct |
94 ms |
131492 KB |
Output is correct |
46 |
Correct |
54 ms |
88968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
724 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1364 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1232 KB |
Output is correct |
26 |
Correct |
1 ms |
1232 KB |
Output is correct |
27 |
Correct |
1 ms |
724 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
1364 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1364 KB |
Output is correct |
34 |
Correct |
1 ms |
1356 KB |
Output is correct |
35 |
Correct |
1 ms |
1408 KB |
Output is correct |
36 |
Correct |
73 ms |
106956 KB |
Output is correct |
37 |
Correct |
42 ms |
65100 KB |
Output is correct |
38 |
Correct |
22 ms |
35052 KB |
Output is correct |
39 |
Correct |
40 ms |
61580 KB |
Output is correct |
40 |
Correct |
53 ms |
79572 KB |
Output is correct |
41 |
Correct |
18 ms |
29964 KB |
Output is correct |
42 |
Correct |
14 ms |
23508 KB |
Output is correct |
43 |
Correct |
19 ms |
29268 KB |
Output is correct |
44 |
Correct |
7 ms |
11476 KB |
Output is correct |
45 |
Correct |
20 ms |
30548 KB |
Output is correct |
46 |
Correct |
16 ms |
21844 KB |
Output is correct |
47 |
Correct |
20 ms |
31224 KB |
Output is correct |
48 |
Correct |
15 ms |
24660 KB |
Output is correct |
49 |
Correct |
18 ms |
29264 KB |
Output is correct |
50 |
Correct |
9 ms |
15572 KB |
Output is correct |
51 |
Correct |
19 ms |
29268 KB |
Output is correct |
52 |
Correct |
6 ms |
10704 KB |
Output is correct |
53 |
Correct |
18 ms |
28624 KB |
Output is correct |
54 |
Correct |
8 ms |
13908 KB |
Output is correct |
55 |
Correct |
18 ms |
30516 KB |
Output is correct |
56 |
Correct |
10 ms |
16996 KB |
Output is correct |
57 |
Correct |
20 ms |
31864 KB |
Output is correct |
58 |
Correct |
13 ms |
18900 KB |
Output is correct |
59 |
Correct |
93 ms |
131660 KB |
Output is correct |
60 |
Correct |
56 ms |
88960 KB |
Output is correct |
61 |
Correct |
101 ms |
131568 KB |
Output is correct |
62 |
Correct |
53 ms |
87892 KB |
Output is correct |
63 |
Correct |
94 ms |
131492 KB |
Output is correct |
64 |
Correct |
54 ms |
88968 KB |
Output is correct |
65 |
Correct |
83 ms |
118992 KB |
Output is correct |
66 |
Correct |
79 ms |
109240 KB |
Output is correct |
67 |
Correct |
73 ms |
104548 KB |
Output is correct |
68 |
Correct |
66 ms |
96604 KB |
Output is correct |
69 |
Correct |
81 ms |
117672 KB |
Output is correct |
70 |
Correct |
80 ms |
112908 KB |
Output is correct |
71 |
Correct |
83 ms |
114016 KB |
Output is correct |
72 |
Correct |
75 ms |
115232 KB |
Output is correct |
73 |
Correct |
69 ms |
106888 KB |
Output is correct |
74 |
Correct |
70 ms |
99948 KB |
Output is correct |
75 |
Correct |
76 ms |
110336 KB |
Output is correct |
76 |
Correct |
88 ms |
126352 KB |
Output is correct |
77 |
Correct |
93 ms |
126412 KB |
Output is correct |
78 |
Correct |
65 ms |
97716 KB |
Output is correct |
79 |
Correct |
70 ms |
101068 KB |
Output is correct |
80 |
Correct |
86 ms |
123912 KB |
Output is correct |
81 |
Correct |
70 ms |
102248 KB |
Output is correct |
82 |
Correct |
79 ms |
108020 KB |
Output is correct |
83 |
Correct |
92 ms |
131588 KB |
Output is correct |
84 |
Correct |
76 ms |
112740 KB |
Output is correct |
85 |
Correct |
83 ms |
122620 KB |
Output is correct |
86 |
Correct |
82 ms |
120064 KB |
Output is correct |
87 |
Correct |
77 ms |
110412 KB |
Output is correct |
88 |
Correct |
96 ms |
132812 KB |
Output is correct |
89 |
Correct |
95 ms |
132896 KB |
Output is correct |
90 |
Correct |
70 ms |
111528 KB |
Output is correct |
91 |
Correct |
95 ms |
132896 KB |
Output is correct |
92 |
Correct |
98 ms |
132888 KB |
Output is correct |
93 |
Correct |
83 ms |
130232 KB |
Output is correct |