#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 200 + 10;
const int inf= 1e9 + 1;
int L;
int dp[maxn][maxn][maxn], pd[maxn][maxn][maxn];
int x[maxn], t[maxn];
int dis(int x, int y){
if (x > y)
swap(x, y);
return min(y - x, L - y + x);
}
int main(){
ios_base::sync_with_stdio(false);
int n;
cin >> n >> L;
for (int i = 1; i <= n; i++)
cin >> x[i];
for (int i = 1; i <= n; i++)
cin >> t[i];
int answer = 0;
x[0] = 0, x[n + 1] = 0;
memset(dp, 63, sizeof dp);
memset(pd, 63, sizeof pd);
dp[0][0][0] = pd[0][0][0] = 0;
for (int i = 0; i <= n; i++){
for (int j = 0; i + j <= n; j++){
if (i + j == 0)
continue;
int iidx = i, jidx = n-j+1;
for (int k = 0; k <= i + j; k++){
if (j > 0){
dp[i][j][k] = min(dp[i][j-1][k] + dis(x[jidx], x[jidx+1]), pd[i][j-1][k] + dis(x[jidx], x[iidx]));
if (k > 0){
if (dp[i][j-1][k-1] + dis(x[jidx], x[jidx+1]) <= t[j])
dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][k-1] + dis(x[jidx], x[jidx+1]));
if (pd[i][j-1][k-1] + dis(x[jidx], x[iidx]) <= t[j])
dp[i][j][k] = min(dp[i][j][k], pd[i][j-1][k-1] + dis(x[jidx], x[iidx]));
}
}
if (i > 0){
pd[i][j][k] = min(pd[i-1][j][k] + dis(x[iidx], x[iidx-1]), dp[i-1][j][k] + dis(x[iidx], x[jidx]));
if (k > 0){
if (pd[i-1][j][k-1] + dis(x[iidx], x[iidx-1]) <= t[i])
pd[i][j][k] = min(pd[i][j][k], pd[i-1][j][k-1] + dis(x[iidx], x[iidx-1]));
if (dp[i-1][j][k-1] + dis(x[iidx], x[jidx]) <= t[i])
pd[i][j][k] = min(pd[i][j][k], dp[i-1][j][k-1] + dis(x[iidx], x[jidx]));
}
}
if (dp[i][j][k] < inf or pd[i][j][k] < inf)
answer = max(answer, k);
}
}
}
cout << answer << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
72824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
72824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
72824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
72824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |