#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
int n=0;
int k=0;
int pos[205];
int limit[205];
int memo[205][205][2][205];
int dp(int l, int r, bool flag, int cur){
if(cur>200) return 0;
if(l+1>=r) return 0;
if(memo[l][r][flag][cur]!=-1) return memo[l][r][flag][cur];
int ans=0;
int dist=cur;
if(!flag) dist+=(pos[l+1]-pos[l]);
else dist+=(pos[l+1]+k-pos[r]);
ans=max(ans,dp(l+1,r,0,dist)+(dist<=limit[l+1]));
int dist2=cur;
if(flag) dist2+=(pos[r]-pos[r-1]);
else dist2+=(pos[l]+k-pos[r-1]);
ans=max(ans,dp(l,r-1,1,dist2)+(dist2<=limit[r-1]));
return memo[l][r][flag][cur]=ans;
}
void solve(){
cin >> n >> k;
memset(memo,-1,sizeof(memo));
for(int x=1;x<=n;x++) cin >> pos[x];
for(int x=1;x<=n;x++) cin >> limit[x];
pos[n+1]=k;
cout << dp(0,n+1,0,0);
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
135252 KB |
Output is correct |
2 |
Correct |
16 ms |
135256 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135260 KB |
Output is correct |
6 |
Correct |
17 ms |
135504 KB |
Output is correct |
7 |
Correct |
18 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135256 KB |
Output is correct |
10 |
Correct |
16 ms |
135084 KB |
Output is correct |
11 |
Correct |
17 ms |
135264 KB |
Output is correct |
12 |
Correct |
16 ms |
135256 KB |
Output is correct |
13 |
Correct |
16 ms |
135260 KB |
Output is correct |
14 |
Correct |
16 ms |
135260 KB |
Output is correct |
15 |
Correct |
18 ms |
135256 KB |
Output is correct |
16 |
Correct |
16 ms |
135260 KB |
Output is correct |
17 |
Correct |
16 ms |
135280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
135252 KB |
Output is correct |
2 |
Correct |
16 ms |
135256 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135260 KB |
Output is correct |
6 |
Correct |
17 ms |
135504 KB |
Output is correct |
7 |
Correct |
18 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135256 KB |
Output is correct |
10 |
Correct |
16 ms |
135084 KB |
Output is correct |
11 |
Correct |
17 ms |
135264 KB |
Output is correct |
12 |
Correct |
16 ms |
135256 KB |
Output is correct |
13 |
Correct |
16 ms |
135260 KB |
Output is correct |
14 |
Correct |
16 ms |
135260 KB |
Output is correct |
15 |
Correct |
18 ms |
135256 KB |
Output is correct |
16 |
Correct |
16 ms |
135260 KB |
Output is correct |
17 |
Correct |
16 ms |
135280 KB |
Output is correct |
18 |
Incorrect |
16 ms |
135260 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
135252 KB |
Output is correct |
2 |
Correct |
16 ms |
135256 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135260 KB |
Output is correct |
6 |
Correct |
17 ms |
135504 KB |
Output is correct |
7 |
Correct |
18 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135256 KB |
Output is correct |
10 |
Correct |
16 ms |
135084 KB |
Output is correct |
11 |
Correct |
17 ms |
135264 KB |
Output is correct |
12 |
Correct |
16 ms |
135256 KB |
Output is correct |
13 |
Correct |
16 ms |
135260 KB |
Output is correct |
14 |
Correct |
16 ms |
135260 KB |
Output is correct |
15 |
Correct |
18 ms |
135256 KB |
Output is correct |
16 |
Correct |
16 ms |
135260 KB |
Output is correct |
17 |
Correct |
16 ms |
135280 KB |
Output is correct |
18 |
Correct |
29 ms |
135260 KB |
Output is correct |
19 |
Correct |
25 ms |
135344 KB |
Output is correct |
20 |
Correct |
22 ms |
135332 KB |
Output is correct |
21 |
Correct |
24 ms |
135260 KB |
Output is correct |
22 |
Correct |
25 ms |
135260 KB |
Output is correct |
23 |
Correct |
26 ms |
135344 KB |
Output is correct |
24 |
Correct |
17 ms |
135260 KB |
Output is correct |
25 |
Correct |
22 ms |
135260 KB |
Output is correct |
26 |
Correct |
17 ms |
135260 KB |
Output is correct |
27 |
Correct |
22 ms |
135224 KB |
Output is correct |
28 |
Correct |
16 ms |
135256 KB |
Output is correct |
29 |
Correct |
22 ms |
135260 KB |
Output is correct |
30 |
Correct |
20 ms |
135520 KB |
Output is correct |
31 |
Correct |
22 ms |
135256 KB |
Output is correct |
32 |
Correct |
17 ms |
135456 KB |
Output is correct |
33 |
Correct |
26 ms |
135332 KB |
Output is correct |
34 |
Correct |
18 ms |
135256 KB |
Output is correct |
35 |
Correct |
21 ms |
135260 KB |
Output is correct |
36 |
Correct |
17 ms |
135124 KB |
Output is correct |
37 |
Correct |
22 ms |
135340 KB |
Output is correct |
38 |
Correct |
18 ms |
135260 KB |
Output is correct |
39 |
Correct |
23 ms |
135260 KB |
Output is correct |
40 |
Correct |
17 ms |
135260 KB |
Output is correct |
41 |
Correct |
30 ms |
135260 KB |
Output is correct |
42 |
Correct |
27 ms |
135188 KB |
Output is correct |
43 |
Correct |
29 ms |
135260 KB |
Output is correct |
44 |
Correct |
26 ms |
135256 KB |
Output is correct |
45 |
Correct |
29 ms |
135260 KB |
Output is correct |
46 |
Correct |
32 ms |
135260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
135252 KB |
Output is correct |
2 |
Correct |
16 ms |
135256 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135260 KB |
Output is correct |
6 |
Correct |
17 ms |
135504 KB |
Output is correct |
7 |
Correct |
18 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135256 KB |
Output is correct |
10 |
Correct |
16 ms |
135084 KB |
Output is correct |
11 |
Correct |
17 ms |
135264 KB |
Output is correct |
12 |
Correct |
16 ms |
135256 KB |
Output is correct |
13 |
Correct |
16 ms |
135260 KB |
Output is correct |
14 |
Correct |
16 ms |
135260 KB |
Output is correct |
15 |
Correct |
18 ms |
135256 KB |
Output is correct |
16 |
Correct |
16 ms |
135260 KB |
Output is correct |
17 |
Correct |
16 ms |
135280 KB |
Output is correct |
18 |
Incorrect |
16 ms |
135260 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |