#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define si second
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 210;
const ll INF=1e18;
int n,l;
int a[N],t[N];
ll dp[N][N][N][2],opt[N],ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n >> l;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> t[i];
for (int i = 0; i <= n+1; ++i) {
for (int j = 0; j <= n+1; ++j) {
for (int k = 0; k <= n+1; ++k) {
dp[i][j][k][0]=INF;
dp[i][j][k][1]=INF;
}
}
}
a[n+1]=l;
dp[0][n+1][0][0]=0;
dp[0][n+1][0][1]=0;
for (int i = 0; i <= n; ++i) {
for (int j = n+1; j >= 1; --j) {
for (int take = 1; take <= n; ++take) {
if (i==0 && j==n+1) continue;
if (take>n-j+i+1) continue;
if (i>=j) continue;
if (i && take) { // go to pref
ll now = dp[i-1][j][take-1][0]+a[i]-a[i-1];
chmin(now, dp[i-1][j][take-1][1]+l-a[j]+a[i]);
if (now <= t[i]) chmin(dp[i][j][take][0], now);
else chmin(dp[i][j][take-1][0], now);
}
if (j<n+1 && take) { // go to suff
ll now = dp[i][j+1][take-1][1]+a[j+1]-a[j];
chmin(now, dp[i][j+1][take-1][0]+l-a[j]+a[i]);
if (now <= t[j]) chmin(dp[i][j][take][1], now);
else chmin(dp[i][j][take-1][1], now);
}
}
}
}
for (int x = 1; x <= n; ++x) {
opt[x]=INF;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n+1; ++j) {
chmin(opt[x],min(dp[i][j][x][0],dp[i][j][x][1]));
}
}
if (opt[x]!=INF) ans = x;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 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 |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 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 |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
976 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
976 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
712 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
1104 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1096 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
1 ms |
1236 KB |
Output is correct |
30 |
Correct |
1 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1096 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
1220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 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 |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
976 KB |
Output is correct |
18 |
Correct |
103 ms |
108704 KB |
Output is correct |
19 |
Correct |
62 ms |
66072 KB |
Output is correct |
20 |
Correct |
33 ms |
35476 KB |
Output is correct |
21 |
Correct |
65 ms |
62468 KB |
Output is correct |
22 |
Correct |
75 ms |
80796 KB |
Output is correct |
23 |
Correct |
23 ms |
30164 KB |
Output is correct |
24 |
Correct |
18 ms |
23636 KB |
Output is correct |
25 |
Correct |
22 ms |
29524 KB |
Output is correct |
26 |
Correct |
7 ms |
11464 KB |
Output is correct |
27 |
Correct |
24 ms |
30792 KB |
Output is correct |
28 |
Correct |
19 ms |
22076 KB |
Output is correct |
29 |
Correct |
24 ms |
31444 KB |
Output is correct |
30 |
Correct |
19 ms |
24888 KB |
Output is correct |
31 |
Correct |
27 ms |
29648 KB |
Output is correct |
32 |
Correct |
11 ms |
15700 KB |
Output is correct |
33 |
Correct |
22 ms |
29524 KB |
Output is correct |
34 |
Correct |
9 ms |
10764 KB |
Output is correct |
35 |
Correct |
26 ms |
29012 KB |
Output is correct |
36 |
Correct |
9 ms |
13896 KB |
Output is correct |
37 |
Correct |
24 ms |
30908 KB |
Output is correct |
38 |
Correct |
13 ms |
17064 KB |
Output is correct |
39 |
Correct |
28 ms |
32068 KB |
Output is correct |
40 |
Correct |
14 ms |
19016 KB |
Output is correct |
41 |
Correct |
133 ms |
133912 KB |
Output is correct |
42 |
Correct |
83 ms |
90512 KB |
Output is correct |
43 |
Correct |
145 ms |
133844 KB |
Output is correct |
44 |
Correct |
103 ms |
89224 KB |
Output is correct |
45 |
Correct |
162 ms |
133816 KB |
Output is correct |
46 |
Correct |
101 ms |
90400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 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 |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
976 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
976 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
712 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
1104 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1096 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
1 ms |
1236 KB |
Output is correct |
30 |
Correct |
1 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1096 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
1220 KB |
Output is correct |
36 |
Correct |
103 ms |
108704 KB |
Output is correct |
37 |
Correct |
62 ms |
66072 KB |
Output is correct |
38 |
Correct |
33 ms |
35476 KB |
Output is correct |
39 |
Correct |
65 ms |
62468 KB |
Output is correct |
40 |
Correct |
75 ms |
80796 KB |
Output is correct |
41 |
Correct |
23 ms |
30164 KB |
Output is correct |
42 |
Correct |
18 ms |
23636 KB |
Output is correct |
43 |
Correct |
22 ms |
29524 KB |
Output is correct |
44 |
Correct |
7 ms |
11464 KB |
Output is correct |
45 |
Correct |
24 ms |
30792 KB |
Output is correct |
46 |
Correct |
19 ms |
22076 KB |
Output is correct |
47 |
Correct |
24 ms |
31444 KB |
Output is correct |
48 |
Correct |
19 ms |
24888 KB |
Output is correct |
49 |
Correct |
27 ms |
29648 KB |
Output is correct |
50 |
Correct |
11 ms |
15700 KB |
Output is correct |
51 |
Correct |
22 ms |
29524 KB |
Output is correct |
52 |
Correct |
9 ms |
10764 KB |
Output is correct |
53 |
Correct |
26 ms |
29012 KB |
Output is correct |
54 |
Correct |
9 ms |
13896 KB |
Output is correct |
55 |
Correct |
24 ms |
30908 KB |
Output is correct |
56 |
Correct |
13 ms |
17064 KB |
Output is correct |
57 |
Correct |
28 ms |
32068 KB |
Output is correct |
58 |
Correct |
14 ms |
19016 KB |
Output is correct |
59 |
Correct |
133 ms |
133912 KB |
Output is correct |
60 |
Correct |
83 ms |
90512 KB |
Output is correct |
61 |
Correct |
145 ms |
133844 KB |
Output is correct |
62 |
Correct |
103 ms |
89224 KB |
Output is correct |
63 |
Correct |
162 ms |
133816 KB |
Output is correct |
64 |
Correct |
101 ms |
90400 KB |
Output is correct |
65 |
Correct |
141 ms |
120972 KB |
Output is correct |
66 |
Correct |
128 ms |
111024 KB |
Output is correct |
67 |
Correct |
118 ms |
106308 KB |
Output is correct |
68 |
Correct |
120 ms |
98192 KB |
Output is correct |
69 |
Correct |
118 ms |
119712 KB |
Output is correct |
70 |
Correct |
99 ms |
114748 KB |
Output is correct |
71 |
Correct |
104 ms |
115960 KB |
Output is correct |
72 |
Correct |
133 ms |
117220 KB |
Output is correct |
73 |
Correct |
109 ms |
108688 KB |
Output is correct |
74 |
Correct |
101 ms |
101580 KB |
Output is correct |
75 |
Correct |
108 ms |
112248 KB |
Output is correct |
76 |
Correct |
127 ms |
128588 KB |
Output is correct |
77 |
Correct |
133 ms |
128672 KB |
Output is correct |
78 |
Correct |
96 ms |
99340 KB |
Output is correct |
79 |
Correct |
102 ms |
102796 KB |
Output is correct |
80 |
Correct |
161 ms |
125976 KB |
Output is correct |
81 |
Correct |
98 ms |
103892 KB |
Output is correct |
82 |
Correct |
120 ms |
109892 KB |
Output is correct |
83 |
Correct |
130 ms |
133904 KB |
Output is correct |
84 |
Correct |
130 ms |
114756 KB |
Output is correct |
85 |
Correct |
133 ms |
124860 KB |
Output is correct |
86 |
Correct |
128 ms |
122136 KB |
Output is correct |
87 |
Correct |
119 ms |
112184 KB |
Output is correct |
88 |
Correct |
162 ms |
135136 KB |
Output is correct |
89 |
Correct |
138 ms |
135236 KB |
Output is correct |
90 |
Correct |
123 ms |
113524 KB |
Output is correct |
91 |
Correct |
144 ms |
135176 KB |
Output is correct |
92 |
Correct |
151 ms |
135240 KB |
Output is correct |
93 |
Correct |
132 ms |
132604 KB |
Output is correct |