#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
//#include "combo.h"
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define p push
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
using namespace std;
const int inf=1e18;
int dp[202][202][202][2],n,m;
int memo[202][202];
//at l r taken ,min time
int caldist(int u,int v){
//dist u->v;
if(u>v)swap(v,u);
if(memo[u][v]!=-1)return memo[u][v];
return memo[u][v]=min((v-u),m-v+u);
}
int32_t main(){
cin>>n>>m;
n++;
vector<pii>v(n);
v[0].f=0,v[0].s=0;
for(int i=1;i<n;i++)cin>>v[i].f;
for(int i=1;i<n;i++)cin>>v[i].s;
for(int i=0;i<=200;i++)for(int j=0;j<=200;j++){
memo[i][j]=-1;
for(int k=0;k<=200;k++)dp[i][j][k][0]=dp[i][j][k][1]=inf;
}
dp[0][0][0][0]=dp[0][0][0][1]=0;
for(int sz=0;sz<n-1;sz++){
int l,r=0,nr,nl;
l=(n-sz)%n;
bool yes=true;
while(yes){
if(l==0)yes=false;
nr=(r+1)%n;
nl=(l-1+n)%n;
for(int t=0;t<=n;t++){
if(dp[l][r][t][0]+caldist(v[nr].f,v[l].f)<=v[nr].s)dp[l][nr][t+1][1]=min(dp[l][nr][t+1][1],dp[l][r][t][0]+caldist(v[nr].f,v[l].f));
else dp[l][nr][t][1]=min(dp[l][nr][t][1],dp[l][r][t][0]+caldist(v[nr].f,v[l].f));//l to nr
if(dp[l][r][t][0]+caldist(v[l].f,v[nl].f)<=v[nl].s)dp[nl][r][t+1][0]=min(dp[nl][r][t+1][0],dp[l][r][t][0]+caldist(v[l].f,v[nl].f));
else dp[nl][r][t][0]=min(dp[nl][r][t][0],dp[l][r][t][0]+caldist(v[l].f,v[nl].f));
if(dp[l][r][t][1]+caldist(v[r].f,v[nl].f)<=v[nl].s)dp[nl][r][t+1][0]=min(dp[nl][r][t+1][0],dp[l][r][t][1]+caldist(v[r].f,v[nl].f));
else dp[nl][r][t][0]=min(dp[nl][r][t][0],dp[l][r][t][1]+caldist(v[r].f,v[nl].f));
if(dp[l][r][t][1]+caldist(v[nr].f,v[r].f)<=v[nr].s)dp[l][nr][t+1][1]=min(dp[l][nr][t+1][1],dp[l][r][t][1]+caldist(v[nr].f,v[r].f));
else dp[l][nr][t][1]=min(dp[l][nr][t][1],dp[l][r][t][1]+caldist(v[nr].f,v[r].f));
}
r=nr;
l=(l+1)%n;
}
}
int ans=0;
for(int i=0;i<=200;i++)for(int j=0;j<=200;j++)for(int k=0;k<=200;k++)for(int g=0;g<2;g++)if(dp[i][j][k][g]<inf)ans=max(ans,k);
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
129116 KB |
Output is correct |
2 |
Correct |
32 ms |
129108 KB |
Output is correct |
3 |
Correct |
35 ms |
129372 KB |
Output is correct |
4 |
Correct |
36 ms |
129124 KB |
Output is correct |
5 |
Correct |
36 ms |
129116 KB |
Output is correct |
6 |
Correct |
30 ms |
129116 KB |
Output is correct |
7 |
Correct |
30 ms |
129116 KB |
Output is correct |
8 |
Correct |
30 ms |
129116 KB |
Output is correct |
9 |
Correct |
34 ms |
129064 KB |
Output is correct |
10 |
Correct |
29 ms |
129116 KB |
Output is correct |
11 |
Correct |
30 ms |
129116 KB |
Output is correct |
12 |
Correct |
38 ms |
128924 KB |
Output is correct |
13 |
Correct |
30 ms |
129116 KB |
Output is correct |
14 |
Correct |
31 ms |
129116 KB |
Output is correct |
15 |
Correct |
30 ms |
129116 KB |
Output is correct |
16 |
Correct |
31 ms |
129116 KB |
Output is correct |
17 |
Correct |
30 ms |
128988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
129116 KB |
Output is correct |
2 |
Correct |
32 ms |
129108 KB |
Output is correct |
3 |
Correct |
35 ms |
129372 KB |
Output is correct |
4 |
Correct |
36 ms |
129124 KB |
Output is correct |
5 |
Correct |
36 ms |
129116 KB |
Output is correct |
6 |
Correct |
30 ms |
129116 KB |
Output is correct |
7 |
Correct |
30 ms |
129116 KB |
Output is correct |
8 |
Correct |
30 ms |
129116 KB |
Output is correct |
9 |
Correct |
34 ms |
129064 KB |
Output is correct |
10 |
Correct |
29 ms |
129116 KB |
Output is correct |
11 |
Correct |
30 ms |
129116 KB |
Output is correct |
12 |
Correct |
38 ms |
128924 KB |
Output is correct |
13 |
Correct |
30 ms |
129116 KB |
Output is correct |
14 |
Correct |
31 ms |
129116 KB |
Output is correct |
15 |
Correct |
30 ms |
129116 KB |
Output is correct |
16 |
Correct |
31 ms |
129116 KB |
Output is correct |
17 |
Correct |
30 ms |
128988 KB |
Output is correct |
18 |
Runtime error |
111 ms |
261656 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
129116 KB |
Output is correct |
2 |
Correct |
32 ms |
129108 KB |
Output is correct |
3 |
Correct |
35 ms |
129372 KB |
Output is correct |
4 |
Correct |
36 ms |
129124 KB |
Output is correct |
5 |
Correct |
36 ms |
129116 KB |
Output is correct |
6 |
Correct |
30 ms |
129116 KB |
Output is correct |
7 |
Correct |
30 ms |
129116 KB |
Output is correct |
8 |
Correct |
30 ms |
129116 KB |
Output is correct |
9 |
Correct |
34 ms |
129064 KB |
Output is correct |
10 |
Correct |
29 ms |
129116 KB |
Output is correct |
11 |
Correct |
30 ms |
129116 KB |
Output is correct |
12 |
Correct |
38 ms |
128924 KB |
Output is correct |
13 |
Correct |
30 ms |
129116 KB |
Output is correct |
14 |
Correct |
31 ms |
129116 KB |
Output is correct |
15 |
Correct |
30 ms |
129116 KB |
Output is correct |
16 |
Correct |
31 ms |
129116 KB |
Output is correct |
17 |
Correct |
30 ms |
128988 KB |
Output is correct |
18 |
Correct |
89 ms |
129112 KB |
Output is correct |
19 |
Correct |
62 ms |
129364 KB |
Output is correct |
20 |
Correct |
45 ms |
129132 KB |
Output is correct |
21 |
Correct |
64 ms |
129368 KB |
Output is correct |
22 |
Correct |
68 ms |
129112 KB |
Output is correct |
23 |
Correct |
41 ms |
129112 KB |
Output is correct |
24 |
Correct |
37 ms |
129116 KB |
Output is correct |
25 |
Correct |
46 ms |
129116 KB |
Output is correct |
26 |
Correct |
36 ms |
129116 KB |
Output is correct |
27 |
Correct |
40 ms |
129112 KB |
Output is correct |
28 |
Correct |
36 ms |
129132 KB |
Output is correct |
29 |
Correct |
40 ms |
129116 KB |
Output is correct |
30 |
Correct |
37 ms |
128980 KB |
Output is correct |
31 |
Correct |
41 ms |
129116 KB |
Output is correct |
32 |
Correct |
36 ms |
129116 KB |
Output is correct |
33 |
Correct |
40 ms |
129352 KB |
Output is correct |
34 |
Correct |
32 ms |
129364 KB |
Output is correct |
35 |
Correct |
38 ms |
129000 KB |
Output is correct |
36 |
Correct |
34 ms |
129116 KB |
Output is correct |
37 |
Correct |
39 ms |
129116 KB |
Output is correct |
38 |
Correct |
34 ms |
129116 KB |
Output is correct |
39 |
Correct |
40 ms |
129116 KB |
Output is correct |
40 |
Correct |
37 ms |
129060 KB |
Output is correct |
41 |
Correct |
132 ms |
129132 KB |
Output is correct |
42 |
Correct |
77 ms |
129132 KB |
Output is correct |
43 |
Correct |
109 ms |
129128 KB |
Output is correct |
44 |
Correct |
74 ms |
129112 KB |
Output is correct |
45 |
Correct |
115 ms |
129116 KB |
Output is correct |
46 |
Correct |
75 ms |
129112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
129116 KB |
Output is correct |
2 |
Correct |
32 ms |
129108 KB |
Output is correct |
3 |
Correct |
35 ms |
129372 KB |
Output is correct |
4 |
Correct |
36 ms |
129124 KB |
Output is correct |
5 |
Correct |
36 ms |
129116 KB |
Output is correct |
6 |
Correct |
30 ms |
129116 KB |
Output is correct |
7 |
Correct |
30 ms |
129116 KB |
Output is correct |
8 |
Correct |
30 ms |
129116 KB |
Output is correct |
9 |
Correct |
34 ms |
129064 KB |
Output is correct |
10 |
Correct |
29 ms |
129116 KB |
Output is correct |
11 |
Correct |
30 ms |
129116 KB |
Output is correct |
12 |
Correct |
38 ms |
128924 KB |
Output is correct |
13 |
Correct |
30 ms |
129116 KB |
Output is correct |
14 |
Correct |
31 ms |
129116 KB |
Output is correct |
15 |
Correct |
30 ms |
129116 KB |
Output is correct |
16 |
Correct |
31 ms |
129116 KB |
Output is correct |
17 |
Correct |
30 ms |
128988 KB |
Output is correct |
18 |
Runtime error |
111 ms |
261656 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |