이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=207, INF=1e9+7;
int X[LIM], T[LIM], dp[LIM][LIM][LIM][2];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, ans=0;
cin >> n >> m;
rep(i, n) cin >> X[i+1];
rep(i, n) cin >> T[i+1];
rep(i, n+1) rep(j, n+1) rep(c, n+1) rep(l, 2) dp[i][j][c][l]=INF;
dp[0][0][0][0]=0;
rep(i, n+1) rep(j, n-i+1) rep(c, i+j+1) rep(l, 2) if(dp[i][j][c][l]<INF) {
ans=max(ans, c);
if(i+j==n) continue;
int x=dp[i][j][c][l];
if(!l) {
dp[i+1][j][c][0]=min(dp[i+1][j][c][0], x+X[i+1]-X[i]);
if(x+X[i+1]-X[i]<=T[i+1]) {
dp[i+1][j][c+1][0]=min(dp[i+1][j][c+1][0], x+X[i+1]-X[i]);
}
dp[i][j+1][c][1]=min(dp[i][j+1][c][1], x+X[i]+m-X[n-j]);
if(x+X[i]+m-X[n-j]<=T[n-j]) {
dp[i][j+1][c+1][1]=min(dp[i][j+1][c+1][1], x+X[i]+m-X[n-j]);
}
} else {
dp[i+1][j][c][0]=min(dp[i+1][j][c][0], x+m-X[n-j+1]+X[i+1]);
if(x+m-X[n-j+1]+X[i+1]<=T[i+1]) {
dp[i+1][j][c+1][0]=min(dp[i+1][j][c+1][0], x+m-X[n-j+1]+X[i+1]);
}
dp[i][j+1][c][1]=min(dp[i][j+1][c][1], x+X[n-j+1]-X[n-j]);
if(x+X[n-j+1]-X[n-j]<=T[n-j]) {
dp[i][j+1][c+1][1]=min(dp[i][j+1][c+1][1], x+X[n-j+1]-X[n-j]);
}
}
}
cout << ans << '\n';
}
# | 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... |