#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _34raRxL ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
void print(){cout<<"\n";}
template<class te,class ...ti>
void print(const te&v,const ti&...nv){cout<<v;if(sizeof...(nv)){cout<<" ";print(nv...);}}
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;
//e
const ll inf=1e18;
ll dp[203][203][203][2];
void chmin(ll &a,ll b){
a=min(a,b);
}
int main(){
_34raRxL;
int n,l;
cin>>n>>l;
vi a(n),ts(n);
{
rep(i,n){
cin>>a[i];
}
a.insert(a.begin(),0);
a.pb(l);
rep(i,n){
cin>>ts[i];
}
ts.insert(ts.begin(),0);
n+=2;
}
rep(i,n)rep(j,n)rep(k,n){
dp[i][j][k][0]=dp[i][j][k][1]=inf;
}
dp[0][n-1][0][0]=dp[0][n-1][0][1]=0;
rep(i,n){
drep(j,n){
rep(k,n-1){
ll vmi=inf,ad=0;
if(i+1<j){
vmi=min(dp[i][j][k][0]+a[i+1]-a[i],dp[i][j][k][1]+l-a[j]+a[i+1]);
ad=(ts[i+1]>=vmi);
chmin(dp[i+1][j][k+ad][0],vmi);
}
vmi=inf;
if(j-1>i){
vmi=min(dp[i][j][k][1]+a[j]-a[j-1],dp[i][j][k][0]+a[i]+l-a[j-1]);
ad=(ts[j-1]>=vmi);
chmin(dp[i][j-1][k+ad][1],vmi);
}
}
}
}
int ans=0;
rep(i,n){
rep(j,n){
rep(k,n-1){
if(dp[i][j][k][0]!=inf or dp[i][j][k][1]!=inf){
ans=max(ans,k);
}
}
}
}
print(ans,"\n");
//
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
652 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
836 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
708 KB |
Output is correct |
9 |
Correct |
1 ms |
836 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
652 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
836 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
708 KB |
Output is correct |
9 |
Correct |
1 ms |
836 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
836 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
708 KB |
Output is correct |
23 |
Correct |
1 ms |
1276 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Correct |
1 ms |
1224 KB |
Output is correct |
30 |
Correct |
1 ms |
1228 KB |
Output is correct |
31 |
Correct |
1 ms |
1100 KB |
Output is correct |
32 |
Correct |
1 ms |
964 KB |
Output is correct |
33 |
Correct |
1 ms |
1228 KB |
Output is correct |
34 |
Correct |
1 ms |
1228 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
652 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
836 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
708 KB |
Output is correct |
9 |
Correct |
1 ms |
836 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
100 ms |
105012 KB |
Output is correct |
19 |
Correct |
56 ms |
63940 KB |
Output is correct |
20 |
Correct |
27 ms |
34364 KB |
Output is correct |
21 |
Correct |
52 ms |
60364 KB |
Output is correct |
22 |
Correct |
78 ms |
78168 KB |
Output is correct |
23 |
Correct |
27 ms |
29280 KB |
Output is correct |
24 |
Correct |
17 ms |
22892 KB |
Output is correct |
25 |
Correct |
22 ms |
28672 KB |
Output is correct |
26 |
Correct |
7 ms |
11084 KB |
Output is correct |
27 |
Correct |
22 ms |
29772 KB |
Output is correct |
28 |
Correct |
14 ms |
21352 KB |
Output is correct |
29 |
Correct |
22 ms |
30392 KB |
Output is correct |
30 |
Correct |
17 ms |
24000 KB |
Output is correct |
31 |
Correct |
22 ms |
28620 KB |
Output is correct |
32 |
Correct |
10 ms |
15172 KB |
Output is correct |
33 |
Correct |
21 ms |
28692 KB |
Output is correct |
34 |
Correct |
6 ms |
10316 KB |
Output is correct |
35 |
Correct |
23 ms |
28084 KB |
Output is correct |
36 |
Correct |
8 ms |
13516 KB |
Output is correct |
37 |
Correct |
23 ms |
29824 KB |
Output is correct |
38 |
Correct |
15 ms |
16444 KB |
Output is correct |
39 |
Correct |
29 ms |
31096 KB |
Output is correct |
40 |
Correct |
12 ms |
18380 KB |
Output is correct |
41 |
Correct |
126 ms |
129408 KB |
Output is correct |
42 |
Correct |
80 ms |
87364 KB |
Output is correct |
43 |
Correct |
128 ms |
129488 KB |
Output is correct |
44 |
Correct |
78 ms |
86372 KB |
Output is correct |
45 |
Correct |
129 ms |
129456 KB |
Output is correct |
46 |
Correct |
79 ms |
87364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
652 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
836 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
708 KB |
Output is correct |
9 |
Correct |
1 ms |
836 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
0 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
836 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
708 KB |
Output is correct |
23 |
Correct |
1 ms |
1276 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Correct |
1 ms |
1224 KB |
Output is correct |
30 |
Correct |
1 ms |
1228 KB |
Output is correct |
31 |
Correct |
1 ms |
1100 KB |
Output is correct |
32 |
Correct |
1 ms |
964 KB |
Output is correct |
33 |
Correct |
1 ms |
1228 KB |
Output is correct |
34 |
Correct |
1 ms |
1228 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
36 |
Correct |
100 ms |
105012 KB |
Output is correct |
37 |
Correct |
56 ms |
63940 KB |
Output is correct |
38 |
Correct |
27 ms |
34364 KB |
Output is correct |
39 |
Correct |
52 ms |
60364 KB |
Output is correct |
40 |
Correct |
78 ms |
78168 KB |
Output is correct |
41 |
Correct |
27 ms |
29280 KB |
Output is correct |
42 |
Correct |
17 ms |
22892 KB |
Output is correct |
43 |
Correct |
22 ms |
28672 KB |
Output is correct |
44 |
Correct |
7 ms |
11084 KB |
Output is correct |
45 |
Correct |
22 ms |
29772 KB |
Output is correct |
46 |
Correct |
14 ms |
21352 KB |
Output is correct |
47 |
Correct |
22 ms |
30392 KB |
Output is correct |
48 |
Correct |
17 ms |
24000 KB |
Output is correct |
49 |
Correct |
22 ms |
28620 KB |
Output is correct |
50 |
Correct |
10 ms |
15172 KB |
Output is correct |
51 |
Correct |
21 ms |
28692 KB |
Output is correct |
52 |
Correct |
6 ms |
10316 KB |
Output is correct |
53 |
Correct |
23 ms |
28084 KB |
Output is correct |
54 |
Correct |
8 ms |
13516 KB |
Output is correct |
55 |
Correct |
23 ms |
29824 KB |
Output is correct |
56 |
Correct |
15 ms |
16444 KB |
Output is correct |
57 |
Correct |
29 ms |
31096 KB |
Output is correct |
58 |
Correct |
12 ms |
18380 KB |
Output is correct |
59 |
Correct |
126 ms |
129408 KB |
Output is correct |
60 |
Correct |
80 ms |
87364 KB |
Output is correct |
61 |
Correct |
128 ms |
129488 KB |
Output is correct |
62 |
Correct |
78 ms |
86372 KB |
Output is correct |
63 |
Correct |
129 ms |
129456 KB |
Output is correct |
64 |
Correct |
79 ms |
87364 KB |
Output is correct |
65 |
Correct |
113 ms |
116964 KB |
Output is correct |
66 |
Correct |
108 ms |
107436 KB |
Output is correct |
67 |
Correct |
101 ms |
102812 KB |
Output is correct |
68 |
Correct |
99 ms |
94972 KB |
Output is correct |
69 |
Correct |
112 ms |
115744 KB |
Output is correct |
70 |
Correct |
105 ms |
110936 KB |
Output is correct |
71 |
Correct |
105 ms |
112156 KB |
Output is correct |
72 |
Correct |
112 ms |
113236 KB |
Output is correct |
73 |
Correct |
99 ms |
105036 KB |
Output is correct |
74 |
Correct |
91 ms |
98232 KB |
Output is correct |
75 |
Correct |
107 ms |
108576 KB |
Output is correct |
76 |
Correct |
126 ms |
124536 KB |
Output is correct |
77 |
Correct |
125 ms |
124516 KB |
Output is correct |
78 |
Correct |
89 ms |
96068 KB |
Output is correct |
79 |
Correct |
93 ms |
99416 KB |
Output is correct |
80 |
Correct |
119 ms |
121896 KB |
Output is correct |
81 |
Correct |
94 ms |
100544 KB |
Output is correct |
82 |
Correct |
111 ms |
106220 KB |
Output is correct |
83 |
Correct |
129 ms |
129488 KB |
Output is correct |
84 |
Correct |
108 ms |
110896 KB |
Output is correct |
85 |
Correct |
118 ms |
120744 KB |
Output is correct |
86 |
Correct |
112 ms |
118088 KB |
Output is correct |
87 |
Correct |
114 ms |
108696 KB |
Output is correct |
88 |
Correct |
136 ms |
130576 KB |
Output is correct |
89 |
Correct |
129 ms |
130636 KB |
Output is correct |
90 |
Correct |
104 ms |
109712 KB |
Output is correct |
91 |
Correct |
153 ms |
130544 KB |
Output is correct |
92 |
Correct |
147 ms |
130628 KB |
Output is correct |
93 |
Correct |
128 ms |
128196 KB |
Output is correct |