#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5+10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n;
vector<ll> arr, tempo;
int dp[405][805], cmp[205];
int calc(int i, int at, ll curr, int nxd, int nxu){
if(i==n) return 0;
if(dp[i][at]!=-1) return dp[i][at];
int valnxd=nxd%n, valnxu=(nxu-1)%n;
int ret=0;
if(tempo[nxd]>=curr+abs(arr[at]-arr[nxd]) && !cmp[valnxd]){
cmp[valnxd]=1;
ret=1+calc(i+1, nxd, curr+abs(arr[at]-arr[nxd]), nxd-1, nxu);
cmp[valnxd]=0;
}
else ret=calc(i+1, nxd, curr+abs(arr[at]-arr[nxd]), nxd-1, nxu);
if(tempo[nxu]>=curr+abs(arr[nxu]-arr[at]) && !cmp[valnxu]){
cmp[valnxu]=1;
ret=max(ret, 1+calc(i+1, nxu, curr+abs(arr[nxu]-arr[at]), nxd, nxu+1));
cmp[valnxu]=0;
}
else ret=max(ret, calc(i+1, nxu, curr+abs(arr[nxu]-arr[at]), nxd, nxu+1));
return dp[i][at]=ret;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// freopen("shuffle.in","r",stdin);
// freopen("shuffle.out","w",stdout);
ll l; cin >> n >> l;
for(int i=0;i<n;i++){
ll x; cin >> x;
arr.pb(x);
}
for(int i=0;i<n;i++) arr.pb(arr[i]+l);
arr.pb(2*l);
for(int i=0;i<n;i++) arr.pb(arr[i]+2*l);
for(int i=0;i<n;i++) arr.pb(arr[i]+3*l);
tempo.resize(4*n+1);
for(int i=0;i<n;i++) cin >> tempo[i];
for(int i=0;i<n;i++) tempo[i+n]=tempo[i];
tempo[2*n]=-1;
for(int i=0;i<n;i++) tempo[i+2*n+1]=tempo[i];
for(int i=0;i<n;i++) tempo[i+3*n+1]=tempo[i];
memset(dp, -1, sizeof dp);
cout << calc(0, 2*n, 0ll, 2*n-1, 2*n+1) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1480 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
1 ms |
1492 KB |
Output is correct |
17 |
Correct |
1 ms |
1556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1480 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
1 ms |
1492 KB |
Output is correct |
17 |
Correct |
1 ms |
1556 KB |
Output is correct |
18 |
Correct |
1 ms |
1492 KB |
Output is correct |
19 |
Correct |
1 ms |
1492 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
1 ms |
1492 KB |
Output is correct |
22 |
Correct |
1 ms |
1492 KB |
Output is correct |
23 |
Correct |
1 ms |
1492 KB |
Output is correct |
24 |
Correct |
1 ms |
1492 KB |
Output is correct |
25 |
Correct |
1 ms |
1492 KB |
Output is correct |
26 |
Incorrect |
1 ms |
1492 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1480 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
1 ms |
1492 KB |
Output is correct |
17 |
Correct |
1 ms |
1556 KB |
Output is correct |
18 |
Incorrect |
2 ms |
1612 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1480 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
1492 KB |
Output is correct |
6 |
Correct |
1 ms |
1492 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
1 ms |
1492 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
1 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1492 KB |
Output is correct |
13 |
Correct |
1 ms |
1492 KB |
Output is correct |
14 |
Correct |
1 ms |
1484 KB |
Output is correct |
15 |
Correct |
1 ms |
1492 KB |
Output is correct |
16 |
Correct |
1 ms |
1492 KB |
Output is correct |
17 |
Correct |
1 ms |
1556 KB |
Output is correct |
18 |
Correct |
1 ms |
1492 KB |
Output is correct |
19 |
Correct |
1 ms |
1492 KB |
Output is correct |
20 |
Correct |
1 ms |
1492 KB |
Output is correct |
21 |
Correct |
1 ms |
1492 KB |
Output is correct |
22 |
Correct |
1 ms |
1492 KB |
Output is correct |
23 |
Correct |
1 ms |
1492 KB |
Output is correct |
24 |
Correct |
1 ms |
1492 KB |
Output is correct |
25 |
Correct |
1 ms |
1492 KB |
Output is correct |
26 |
Incorrect |
1 ms |
1492 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |