#pragma.GCCoptimise("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
using namespace std;
ll n,m,k,i,j,ans,a[205],t[205],d[205][205][2][205];
ll check(int l, int r, int pos, int cnt){
if(cnt==0)return 1e14;
if(l>r)return -1e14;
if(d[l][r][pos][cnt]!=-1)return d[l][r][pos][cnt];
ll ans=-1e14;
int lc;
if(pos==0) lc=l-1;
else lc=r+1;
ans=max(ans,check(l+1,r,0,cnt)-(min(abs(a[l]-a[lc]),m-abs(a[l]-a[lc]))));
ans=max(ans,check(l,r-1,1,cnt)-(min(abs(a[r]-a[lc]),m-abs(a[r]-a[lc]))));
ans=max(ans,min(t[l],check(l+1,r,0,cnt-1))-(min(abs(a[l]-a[lc]),m-abs(a[l]-a[lc]))));
ans=max(ans,min(t[r],check(l,r-1,1,cnt-1))-(min(abs(a[r]-a[lc]),m-abs(a[r]-a[lc]))));
d[l][r][pos][cnt]=ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(k=0; k<n; k++)cin>>a[k];
for(k=0; k<n; k++)cin>>t[k];
memset(d,-1,sizeof d);
ll fans=0;
for(k=0; k<=n; k++) {
if(check(0,n-1,1,k)>=0)fans=k;}
cout<<fans;
}
Compilation message
ho_t3.cpp:1: warning: ignoring '#pragma . GCCoptimise' [-Wunknown-pragmas]
1 | #pragma.GCCoptimise("Ofast")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
135248 KB |
Output is correct |
2 |
Correct |
57 ms |
135256 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
63 ms |
135252 KB |
Output is correct |
5 |
Correct |
61 ms |
135164 KB |
Output is correct |
6 |
Correct |
59 ms |
135248 KB |
Output is correct |
7 |
Correct |
65 ms |
135248 KB |
Output is correct |
8 |
Correct |
61 ms |
135248 KB |
Output is correct |
9 |
Correct |
60 ms |
135232 KB |
Output is correct |
10 |
Correct |
60 ms |
135252 KB |
Output is correct |
11 |
Correct |
61 ms |
135248 KB |
Output is correct |
12 |
Correct |
60 ms |
135060 KB |
Output is correct |
13 |
Correct |
63 ms |
135252 KB |
Output is correct |
14 |
Correct |
62 ms |
135224 KB |
Output is correct |
15 |
Correct |
62 ms |
135252 KB |
Output is correct |
16 |
Correct |
59 ms |
135248 KB |
Output is correct |
17 |
Correct |
64 ms |
135184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
135248 KB |
Output is correct |
2 |
Correct |
57 ms |
135256 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
63 ms |
135252 KB |
Output is correct |
5 |
Correct |
61 ms |
135164 KB |
Output is correct |
6 |
Correct |
59 ms |
135248 KB |
Output is correct |
7 |
Correct |
65 ms |
135248 KB |
Output is correct |
8 |
Correct |
61 ms |
135248 KB |
Output is correct |
9 |
Correct |
60 ms |
135232 KB |
Output is correct |
10 |
Correct |
60 ms |
135252 KB |
Output is correct |
11 |
Correct |
61 ms |
135248 KB |
Output is correct |
12 |
Correct |
60 ms |
135060 KB |
Output is correct |
13 |
Correct |
63 ms |
135252 KB |
Output is correct |
14 |
Correct |
62 ms |
135224 KB |
Output is correct |
15 |
Correct |
62 ms |
135252 KB |
Output is correct |
16 |
Correct |
59 ms |
135248 KB |
Output is correct |
17 |
Correct |
64 ms |
135184 KB |
Output is correct |
18 |
Correct |
60 ms |
135292 KB |
Output is correct |
19 |
Correct |
68 ms |
135300 KB |
Output is correct |
20 |
Correct |
64 ms |
135212 KB |
Output is correct |
21 |
Correct |
65 ms |
135252 KB |
Output is correct |
22 |
Correct |
60 ms |
135076 KB |
Output is correct |
23 |
Correct |
62 ms |
135248 KB |
Output is correct |
24 |
Correct |
61 ms |
135136 KB |
Output is correct |
25 |
Correct |
62 ms |
135076 KB |
Output is correct |
26 |
Correct |
59 ms |
135248 KB |
Output is correct |
27 |
Correct |
71 ms |
135252 KB |
Output is correct |
28 |
Correct |
62 ms |
135248 KB |
Output is correct |
29 |
Correct |
61 ms |
135252 KB |
Output is correct |
30 |
Correct |
61 ms |
135264 KB |
Output is correct |
31 |
Correct |
60 ms |
135252 KB |
Output is correct |
32 |
Correct |
67 ms |
135308 KB |
Output is correct |
33 |
Correct |
64 ms |
135248 KB |
Output is correct |
34 |
Correct |
63 ms |
135252 KB |
Output is correct |
35 |
Correct |
65 ms |
135252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
135248 KB |
Output is correct |
2 |
Correct |
57 ms |
135256 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
63 ms |
135252 KB |
Output is correct |
5 |
Correct |
61 ms |
135164 KB |
Output is correct |
6 |
Correct |
59 ms |
135248 KB |
Output is correct |
7 |
Correct |
65 ms |
135248 KB |
Output is correct |
8 |
Correct |
61 ms |
135248 KB |
Output is correct |
9 |
Correct |
60 ms |
135232 KB |
Output is correct |
10 |
Correct |
60 ms |
135252 KB |
Output is correct |
11 |
Correct |
61 ms |
135248 KB |
Output is correct |
12 |
Correct |
60 ms |
135060 KB |
Output is correct |
13 |
Correct |
63 ms |
135252 KB |
Output is correct |
14 |
Correct |
62 ms |
135224 KB |
Output is correct |
15 |
Correct |
62 ms |
135252 KB |
Output is correct |
16 |
Correct |
59 ms |
135248 KB |
Output is correct |
17 |
Correct |
64 ms |
135184 KB |
Output is correct |
18 |
Correct |
195 ms |
135248 KB |
Output is correct |
19 |
Correct |
130 ms |
135508 KB |
Output is correct |
20 |
Correct |
85 ms |
135248 KB |
Output is correct |
21 |
Correct |
117 ms |
135304 KB |
Output is correct |
22 |
Correct |
142 ms |
135248 KB |
Output is correct |
23 |
Correct |
83 ms |
135240 KB |
Output is correct |
24 |
Correct |
80 ms |
135124 KB |
Output is correct |
25 |
Correct |
76 ms |
135248 KB |
Output is correct |
26 |
Correct |
67 ms |
135264 KB |
Output is correct |
27 |
Correct |
85 ms |
135180 KB |
Output is correct |
28 |
Correct |
77 ms |
135248 KB |
Output is correct |
29 |
Correct |
83 ms |
135248 KB |
Output is correct |
30 |
Correct |
77 ms |
135248 KB |
Output is correct |
31 |
Correct |
80 ms |
135252 KB |
Output is correct |
32 |
Correct |
75 ms |
135248 KB |
Output is correct |
33 |
Correct |
85 ms |
135252 KB |
Output is correct |
34 |
Correct |
69 ms |
135252 KB |
Output is correct |
35 |
Correct |
81 ms |
135248 KB |
Output is correct |
36 |
Correct |
71 ms |
135256 KB |
Output is correct |
37 |
Correct |
88 ms |
135252 KB |
Output is correct |
38 |
Correct |
72 ms |
135248 KB |
Output is correct |
39 |
Correct |
86 ms |
135316 KB |
Output is correct |
40 |
Correct |
75 ms |
135248 KB |
Output is correct |
41 |
Correct |
227 ms |
135248 KB |
Output is correct |
42 |
Correct |
187 ms |
135252 KB |
Output is correct |
43 |
Correct |
215 ms |
135248 KB |
Output is correct |
44 |
Correct |
149 ms |
135248 KB |
Output is correct |
45 |
Correct |
218 ms |
135316 KB |
Output is correct |
46 |
Correct |
153 ms |
135252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
135248 KB |
Output is correct |
2 |
Correct |
57 ms |
135256 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
63 ms |
135252 KB |
Output is correct |
5 |
Correct |
61 ms |
135164 KB |
Output is correct |
6 |
Correct |
59 ms |
135248 KB |
Output is correct |
7 |
Correct |
65 ms |
135248 KB |
Output is correct |
8 |
Correct |
61 ms |
135248 KB |
Output is correct |
9 |
Correct |
60 ms |
135232 KB |
Output is correct |
10 |
Correct |
60 ms |
135252 KB |
Output is correct |
11 |
Correct |
61 ms |
135248 KB |
Output is correct |
12 |
Correct |
60 ms |
135060 KB |
Output is correct |
13 |
Correct |
63 ms |
135252 KB |
Output is correct |
14 |
Correct |
62 ms |
135224 KB |
Output is correct |
15 |
Correct |
62 ms |
135252 KB |
Output is correct |
16 |
Correct |
59 ms |
135248 KB |
Output is correct |
17 |
Correct |
64 ms |
135184 KB |
Output is correct |
18 |
Correct |
60 ms |
135292 KB |
Output is correct |
19 |
Correct |
68 ms |
135300 KB |
Output is correct |
20 |
Correct |
64 ms |
135212 KB |
Output is correct |
21 |
Correct |
65 ms |
135252 KB |
Output is correct |
22 |
Correct |
60 ms |
135076 KB |
Output is correct |
23 |
Correct |
62 ms |
135248 KB |
Output is correct |
24 |
Correct |
61 ms |
135136 KB |
Output is correct |
25 |
Correct |
62 ms |
135076 KB |
Output is correct |
26 |
Correct |
59 ms |
135248 KB |
Output is correct |
27 |
Correct |
71 ms |
135252 KB |
Output is correct |
28 |
Correct |
62 ms |
135248 KB |
Output is correct |
29 |
Correct |
61 ms |
135252 KB |
Output is correct |
30 |
Correct |
61 ms |
135264 KB |
Output is correct |
31 |
Correct |
60 ms |
135252 KB |
Output is correct |
32 |
Correct |
67 ms |
135308 KB |
Output is correct |
33 |
Correct |
64 ms |
135248 KB |
Output is correct |
34 |
Correct |
63 ms |
135252 KB |
Output is correct |
35 |
Correct |
65 ms |
135252 KB |
Output is correct |
36 |
Correct |
195 ms |
135248 KB |
Output is correct |
37 |
Correct |
130 ms |
135508 KB |
Output is correct |
38 |
Correct |
85 ms |
135248 KB |
Output is correct |
39 |
Correct |
117 ms |
135304 KB |
Output is correct |
40 |
Correct |
142 ms |
135248 KB |
Output is correct |
41 |
Correct |
83 ms |
135240 KB |
Output is correct |
42 |
Correct |
80 ms |
135124 KB |
Output is correct |
43 |
Correct |
76 ms |
135248 KB |
Output is correct |
44 |
Correct |
67 ms |
135264 KB |
Output is correct |
45 |
Correct |
85 ms |
135180 KB |
Output is correct |
46 |
Correct |
77 ms |
135248 KB |
Output is correct |
47 |
Correct |
83 ms |
135248 KB |
Output is correct |
48 |
Correct |
77 ms |
135248 KB |
Output is correct |
49 |
Correct |
80 ms |
135252 KB |
Output is correct |
50 |
Correct |
75 ms |
135248 KB |
Output is correct |
51 |
Correct |
85 ms |
135252 KB |
Output is correct |
52 |
Correct |
69 ms |
135252 KB |
Output is correct |
53 |
Correct |
81 ms |
135248 KB |
Output is correct |
54 |
Correct |
71 ms |
135256 KB |
Output is correct |
55 |
Correct |
88 ms |
135252 KB |
Output is correct |
56 |
Correct |
72 ms |
135248 KB |
Output is correct |
57 |
Correct |
86 ms |
135316 KB |
Output is correct |
58 |
Correct |
75 ms |
135248 KB |
Output is correct |
59 |
Correct |
227 ms |
135248 KB |
Output is correct |
60 |
Correct |
187 ms |
135252 KB |
Output is correct |
61 |
Correct |
215 ms |
135248 KB |
Output is correct |
62 |
Correct |
149 ms |
135248 KB |
Output is correct |
63 |
Correct |
218 ms |
135316 KB |
Output is correct |
64 |
Correct |
153 ms |
135252 KB |
Output is correct |
65 |
Correct |
191 ms |
135120 KB |
Output is correct |
66 |
Correct |
224 ms |
135304 KB |
Output is correct |
67 |
Correct |
173 ms |
135252 KB |
Output is correct |
68 |
Correct |
150 ms |
135328 KB |
Output is correct |
69 |
Correct |
194 ms |
135220 KB |
Output is correct |
70 |
Correct |
179 ms |
135504 KB |
Output is correct |
71 |
Correct |
170 ms |
135248 KB |
Output is correct |
72 |
Correct |
182 ms |
135236 KB |
Output is correct |
73 |
Correct |
162 ms |
135248 KB |
Output is correct |
74 |
Correct |
159 ms |
135248 KB |
Output is correct |
75 |
Correct |
180 ms |
135504 KB |
Output is correct |
76 |
Correct |
200 ms |
135248 KB |
Output is correct |
77 |
Correct |
196 ms |
135252 KB |
Output is correct |
78 |
Correct |
161 ms |
135332 KB |
Output is correct |
79 |
Correct |
158 ms |
135252 KB |
Output is correct |
80 |
Correct |
190 ms |
135128 KB |
Output is correct |
81 |
Correct |
168 ms |
135148 KB |
Output is correct |
82 |
Correct |
175 ms |
135248 KB |
Output is correct |
83 |
Correct |
209 ms |
135248 KB |
Output is correct |
84 |
Correct |
177 ms |
135252 KB |
Output is correct |
85 |
Correct |
201 ms |
135348 KB |
Output is correct |
86 |
Correct |
190 ms |
135252 KB |
Output is correct |
87 |
Correct |
185 ms |
135244 KB |
Output is correct |
88 |
Correct |
206 ms |
135244 KB |
Output is correct |
89 |
Correct |
213 ms |
135096 KB |
Output is correct |
90 |
Correct |
191 ms |
135252 KB |
Output is correct |
91 |
Correct |
229 ms |
135100 KB |
Output is correct |
92 |
Correct |
231 ms |
135228 KB |
Output is correct |
93 |
Correct |
199 ms |
135248 KB |
Output is correct |