#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
#define sz(a) (int)a.size()
const int mxN = (int)4e2+10;
const int LINF = (int)1e18;
pair<int,int> dp[mxN][mxN][2];
int x[mxN], t[mxN];
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, L; cin >> n >> L; int ans = 0;
for(int i = 1; i <= n; i++) cin >> x[i], x[n+i+1]=x[i];
for(int i = 1; i <= n; i++) cin >> t[i], t[n+i+1]=t[i];
for(int i = 1; i <= 2*n; i++)
for(int j = i; j <= 2*n; j++)
for(int k = 0; k < 2; k++)
dp[i][j][k] = mp(-LINF,LINF);
dp[n+1][n+1][0]=dp[n+1][n+1][1]=mp(0,0);
t[n+1] = -LINF;
for(int len = 2; len <= n+1; len++){
for(int l = 1; l <= n+1; l++){
int r = l+len-1;
dp[l][r][0] = max(
mp(dp[l+1][r][0].fi+(dp[l+1][r][0].se+min(abs(x[l+1]-x[l]),L-abs(x[l+1]-x[l]))<=t[l]),
dp[l+1][r][0].se+min(abs(x[l+1]-x[l]),L-abs(x[l+1]-x[l]))),
mp(dp[l+1][r][1].fi+(dp[l+1][r][1].se+min(abs(x[r]-x[l]),L-abs(x[r]-x[l]))<=t[l]),
dp[l+1][r][1].se+min(abs(x[r]-x[l]),L-abs(x[r]-x[l])))
);
dp[l][r][1] = max(
mp(dp[l][r-1][0].fi+(dp[l][r-1][0].se+min(abs(x[l]-x[r]),L-abs(x[l]-x[r]))<=t[r]),
dp[l][r-1][0].se+min(abs(x[l]-x[r]),L-abs(x[l]-x[r]))),
mp(dp[l][r-1][1].fi+(dp[l][r-1][1].se+min(abs(x[r-1]-x[r]),L-abs(x[r-1]-x[r]))<=t[r]),
dp[l][r-1][1].se+min(abs(x[r-1]-x[r]),L-abs(x[r-1]-x[r])))
);
if(len==n+1) ans = max({ans, dp[l][r][0].fi, dp[l][r][1].fi});
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Incorrect |
2 ms |
3668 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
324 KB |
Output is correct |
18 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |