이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |