#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);
using namespace std;
const int inf=1e9;
int dp[202][202][202][2],n,m;
int memo[202][202];
//at l r taken ,min time
vector<pii>v(202);
int caldist(int a,int b){
//dist u->v;
a=v[a].f,b=v[b].f;
if(a>b)swap(a,b);
if(memo[a][b]!=-1)return memo[a][b];
return memo[a][b]=min((b-a),m-b+a);
}
int32_t main(){
cin>>n>>m;
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(nr,l)<=v[nr].s)dp[l][nr][t+1][1]=min(dp[l][nr][t+1][1],dp[l][r][t][0]+caldist(nr,l));
else dp[l][nr][t][1]=min(dp[l][nr][t][1],dp[l][r][t][0]+caldist(nr,l));//l to nr
if(dp[l][r][t][0]+caldist(l,nl)<=v[nl].s)dp[nl][r][t+1][0]=min(dp[nl][r][t+1][0],dp[l][r][t][0]+caldist(l,nl));
else dp[nl][r][t][0]=min(dp[nl][r][t][0],dp[l][r][t][0]+caldist(l,nl));
if(dp[l][r][t][1]+caldist(r,nl)<=v[nl].s)dp[nl][r][t+1][0]=min(dp[nl][r][t+1][0],dp[l][r][t][1]+caldist(r,nl));
else dp[nl][r][t][0]=min(dp[nl][r][t][0],dp[l][r][t][1]+caldist(r,nl));
if(dp[l][r][t][1]+caldist(nr,r)<=v[nr].s)dp[l][nr][t+1][1]=min(dp[l][nr][t+1][1],dp[l][r][t][1]+caldist(nr,r));
else dp[l][nr][t][1]=min(dp[l][nr][t][1],dp[l][r][t][1]+caldist(nr,r));
}
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 |
20 ms |
64604 KB |
Output is correct |
2 |
Correct |
20 ms |
64604 KB |
Output is correct |
3 |
Correct |
22 ms |
64600 KB |
Output is correct |
4 |
Correct |
20 ms |
64604 KB |
Output is correct |
5 |
Correct |
21 ms |
64604 KB |
Output is correct |
6 |
Correct |
20 ms |
64600 KB |
Output is correct |
7 |
Correct |
20 ms |
64604 KB |
Output is correct |
8 |
Correct |
20 ms |
64600 KB |
Output is correct |
9 |
Correct |
20 ms |
64604 KB |
Output is correct |
10 |
Correct |
21 ms |
64804 KB |
Output is correct |
11 |
Correct |
20 ms |
64604 KB |
Output is correct |
12 |
Correct |
21 ms |
64604 KB |
Output is correct |
13 |
Correct |
20 ms |
64604 KB |
Output is correct |
14 |
Correct |
20 ms |
64804 KB |
Output is correct |
15 |
Correct |
20 ms |
64600 KB |
Output is correct |
16 |
Correct |
20 ms |
64600 KB |
Output is correct |
17 |
Correct |
20 ms |
64604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
64604 KB |
Output is correct |
2 |
Correct |
20 ms |
64604 KB |
Output is correct |
3 |
Correct |
22 ms |
64600 KB |
Output is correct |
4 |
Correct |
20 ms |
64604 KB |
Output is correct |
5 |
Correct |
21 ms |
64604 KB |
Output is correct |
6 |
Correct |
20 ms |
64600 KB |
Output is correct |
7 |
Correct |
20 ms |
64604 KB |
Output is correct |
8 |
Correct |
20 ms |
64600 KB |
Output is correct |
9 |
Correct |
20 ms |
64604 KB |
Output is correct |
10 |
Correct |
21 ms |
64804 KB |
Output is correct |
11 |
Correct |
20 ms |
64604 KB |
Output is correct |
12 |
Correct |
21 ms |
64604 KB |
Output is correct |
13 |
Correct |
20 ms |
64604 KB |
Output is correct |
14 |
Correct |
20 ms |
64804 KB |
Output is correct |
15 |
Correct |
20 ms |
64600 KB |
Output is correct |
16 |
Correct |
20 ms |
64600 KB |
Output is correct |
17 |
Correct |
20 ms |
64604 KB |
Output is correct |
18 |
Runtime error |
60 ms |
130900 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
64604 KB |
Output is correct |
2 |
Correct |
20 ms |
64604 KB |
Output is correct |
3 |
Correct |
22 ms |
64600 KB |
Output is correct |
4 |
Correct |
20 ms |
64604 KB |
Output is correct |
5 |
Correct |
21 ms |
64604 KB |
Output is correct |
6 |
Correct |
20 ms |
64600 KB |
Output is correct |
7 |
Correct |
20 ms |
64604 KB |
Output is correct |
8 |
Correct |
20 ms |
64600 KB |
Output is correct |
9 |
Correct |
20 ms |
64604 KB |
Output is correct |
10 |
Correct |
21 ms |
64804 KB |
Output is correct |
11 |
Correct |
20 ms |
64604 KB |
Output is correct |
12 |
Correct |
21 ms |
64604 KB |
Output is correct |
13 |
Correct |
20 ms |
64604 KB |
Output is correct |
14 |
Correct |
20 ms |
64804 KB |
Output is correct |
15 |
Correct |
20 ms |
64600 KB |
Output is correct |
16 |
Correct |
20 ms |
64600 KB |
Output is correct |
17 |
Correct |
20 ms |
64604 KB |
Output is correct |
18 |
Correct |
85 ms |
64792 KB |
Output is correct |
19 |
Correct |
49 ms |
64776 KB |
Output is correct |
20 |
Correct |
31 ms |
64648 KB |
Output is correct |
21 |
Correct |
45 ms |
64604 KB |
Output is correct |
22 |
Correct |
58 ms |
64856 KB |
Output is correct |
23 |
Correct |
29 ms |
64600 KB |
Output is correct |
24 |
Correct |
26 ms |
64600 KB |
Output is correct |
25 |
Correct |
29 ms |
64600 KB |
Output is correct |
26 |
Correct |
23 ms |
64600 KB |
Output is correct |
27 |
Correct |
31 ms |
64604 KB |
Output is correct |
28 |
Correct |
26 ms |
64600 KB |
Output is correct |
29 |
Correct |
36 ms |
64672 KB |
Output is correct |
30 |
Correct |
28 ms |
64600 KB |
Output is correct |
31 |
Correct |
30 ms |
64600 KB |
Output is correct |
32 |
Correct |
28 ms |
64804 KB |
Output is correct |
33 |
Correct |
29 ms |
64604 KB |
Output is correct |
34 |
Correct |
22 ms |
64604 KB |
Output is correct |
35 |
Correct |
32 ms |
64604 KB |
Output is correct |
36 |
Correct |
29 ms |
64604 KB |
Output is correct |
37 |
Correct |
32 ms |
64604 KB |
Output is correct |
38 |
Correct |
24 ms |
64604 KB |
Output is correct |
39 |
Correct |
29 ms |
64600 KB |
Output is correct |
40 |
Correct |
24 ms |
64852 KB |
Output is correct |
41 |
Correct |
103 ms |
64756 KB |
Output is correct |
42 |
Correct |
72 ms |
64796 KB |
Output is correct |
43 |
Correct |
101 ms |
64600 KB |
Output is correct |
44 |
Correct |
67 ms |
64780 KB |
Output is correct |
45 |
Correct |
98 ms |
64604 KB |
Output is correct |
46 |
Correct |
70 ms |
64604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
64604 KB |
Output is correct |
2 |
Correct |
20 ms |
64604 KB |
Output is correct |
3 |
Correct |
22 ms |
64600 KB |
Output is correct |
4 |
Correct |
20 ms |
64604 KB |
Output is correct |
5 |
Correct |
21 ms |
64604 KB |
Output is correct |
6 |
Correct |
20 ms |
64600 KB |
Output is correct |
7 |
Correct |
20 ms |
64604 KB |
Output is correct |
8 |
Correct |
20 ms |
64600 KB |
Output is correct |
9 |
Correct |
20 ms |
64604 KB |
Output is correct |
10 |
Correct |
21 ms |
64804 KB |
Output is correct |
11 |
Correct |
20 ms |
64604 KB |
Output is correct |
12 |
Correct |
21 ms |
64604 KB |
Output is correct |
13 |
Correct |
20 ms |
64604 KB |
Output is correct |
14 |
Correct |
20 ms |
64804 KB |
Output is correct |
15 |
Correct |
20 ms |
64600 KB |
Output is correct |
16 |
Correct |
20 ms |
64600 KB |
Output is correct |
17 |
Correct |
20 ms |
64604 KB |
Output is correct |
18 |
Runtime error |
60 ms |
130900 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |