This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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], x[i]-=L;
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |