#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 205, INF = 1e18;
ll n, l;
ll cl[N], ccl[N], t[N];
void read() {
cin >> n >> l;
cl[0] = 0, cl[n+1] = l;
ccl[0] = l, cl[n+1] = 0;
for(int i = 1; i <= n; i++) {
cin >> cl[i];
ccl[i] = l - cl[i];
}
for(int i = 1; i <= n; i++)
cin >> t[i];
}
struct state {
int l, r, cnt, dir;
state(int _l, int _r, int _cnt, int _dir) : l(_l), r(_r), cnt(_cnt), dir(_dir) {}
bool operator<(const state& ot) const {
return cnt < ot.cnt;
}
};
void solve() {
priority_queue<pair<ll, state>, vector<pair<ll, state>>, greater<pair<ll, state>>> pq;
ll dp[n+2][n+2][n+2][2];
for(int l = 0; l <= n+1; l++) {
for(int r = 0; r <= n+1; r++) {
for(int cnt = 0; cnt <= n; cnt++)
dp[l][r][cnt][0] = dp[l][r][cnt][1] = INF;
}
}
dp[0][n+1][0][0] = 0;
for(int l = 0; l <= n+1; l++) {
for(int r = n+1; r > l; r--) {
for(int cnt = 0; cnt <= n; cnt++) {
// cerr << l << ' ' << r << ' ' << cnt << '\n';
ll dur;
if(dp[l][r][cnt][0] < INF) {
dur = dp[l][r][cnt][0] + cl[l + 1] - cl[l];
dp[l + 1][r][cnt + (dur <= t[l + 1])][0] = min(dp[l + 1][r][cnt + (dur <= t[l + 1])][0], dur);
dur = dp[l][r][cnt][0] + cl[l] + ccl[r - 1];
dp[l][r - 1][cnt + (dur <= t[r - 1])][1] = min(dp[l][r - 1][cnt + (dur <= t[r - 1])][1], dur);
}
if(dp[l][r][cnt][1] < INF) {
dur = dp[l][r][cnt][1] + ccl[r - 1] - ccl[r];
dp[l][r - 1][cnt + (dur <= t[r - 1])][1] = min(dp[l][r - 1][cnt + (dur <= t[r - 1])][1], dur);
dur = dp[l][r][cnt][1] + ccl[r] + cl[l + 1];
dp[l + 1][r][cnt + (dur <= t[l + 1])][0] = min(dp[l + 1][r][cnt + (dur <= t[l + 1])][0], dur);
}
}
}
}
ll ans = 0;
for(int l = 0; l <= n; l++) {
for(int r = 0; r <= n; r++) {
for(int cnt = 0; cnt <= n; cnt++) {
if(min(dp[l][r][cnt][0], dp[l][r][cnt][1]) < INF)
ans = max(ans, (ll)cnt);
}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |