#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
struct State{
ll dist;
int to_left;
int to_right;
int collect;
int side;
bool operator< (const State &Q) const {
return dist > Q.dist;
}
};
const int N = 201;
const ll inf = (ll)1e18;
ll dp[N][N][N][2];
ll x[N], t[N];
priority_queue<State> bf;
void upd_state(State nx){
if(nx.dist < dp[nx.to_left][nx.to_right][nx.collect][nx.side]){
dp[nx.to_left][nx.to_right][nx.collect][nx.side] = nx.dist;
bf.push(nx);
}
}
int main(){
fastIO;
int n;
ll d;
cin >> n >> d;
for(int i = 1 ; i <= n; i ++ ){
cin >> x[i];
}
for(int i = 1; i <= n; i ++ ){
cin >> t[i];
}
for(int i = 0 ; i <= n; i ++ ){
for(int j = 0 ; j <= n; j ++ ){
for(int k = 0; k <= n; k ++ ){
for(int b = 0; b < 2; b ++ ){
dp[i][j][k][b] = inf;
}
}
}
}
int m = (n + 1);
x[m]=d,t[m]=0;
x[0]=0,t[0]=0;
int ans = 0;
upd_state({0, 0, 0, 0, 0});
State cur;
State nx;
int dnw;
while(!bf.empty()){
cur = bf.top();
bf.pop();
ans = max(ans, cur.collect);
if(cur.dist != dp[cur.to_left][cur.to_right][cur.collect][cur.side])
continue;
upd_state({cur.dist + x[cur.to_right] + d-x[m - cur.to_left], cur.to_left, cur.to_right, cur.collect, cur.side ^ 1});
if(cur.to_left + cur.to_right < n){
if(cur.side == 1){
nx = {cur.dist, cur.to_left, cur.to_right + 1, cur.collect, 1};
dnw = x[cur.to_right+1] - x[cur.to_right] + cur.dist;
nx.dist = dnw;
if(dnw <= t[cur.to_right + 1])
nx.collect ++ ;
upd_state(nx);
}
if(cur.side == 0){
nx = {cur.dist, cur.to_left + 1, cur.to_right, cur.collect, 0};
dnw = x[m - cur.to_left]-x[m - cur.to_left - 1] + cur.dist;
nx.dist = dnw;
if(dnw <= t[m - cur.to_left - 1])
nx.collect ++ ;
upd_state(nx);
}
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 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 |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 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 |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
896 KB |
Output is correct |
18 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 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 |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
896 KB |
Output is correct |
18 |
Correct |
618 ms |
115552 KB |
Output is correct |
19 |
Correct |
291 ms |
68832 KB |
Output is correct |
20 |
Correct |
89 ms |
36588 KB |
Output is correct |
21 |
Correct |
212 ms |
65252 KB |
Output is correct |
22 |
Correct |
391 ms |
88996 KB |
Output is correct |
23 |
Correct |
42 ms |
30064 KB |
Output is correct |
24 |
Correct |
37 ms |
23928 KB |
Output is correct |
25 |
Correct |
44 ms |
29552 KB |
Output is correct |
26 |
Correct |
14 ms |
11200 KB |
Output is correct |
27 |
Correct |
45 ms |
30708 KB |
Output is correct |
28 |
Correct |
32 ms |
22392 KB |
Output is correct |
29 |
Correct |
71 ms |
31344 KB |
Output is correct |
30 |
Correct |
40 ms |
24944 KB |
Output is correct |
31 |
Correct |
67 ms |
29552 KB |
Output is correct |
32 |
Correct |
29 ms |
15612 KB |
Output is correct |
33 |
Correct |
69 ms |
29552 KB |
Output is correct |
34 |
Correct |
14 ms |
10876 KB |
Output is correct |
35 |
Correct |
29 ms |
27832 KB |
Output is correct |
36 |
Correct |
24 ms |
13948 KB |
Output is correct |
37 |
Correct |
32 ms |
29948 KB |
Output is correct |
38 |
Correct |
25 ms |
16892 KB |
Output is correct |
39 |
Correct |
33 ms |
31092 KB |
Output is correct |
40 |
Correct |
24 ms |
18684 KB |
Output is correct |
41 |
Correct |
889 ms |
151660 KB |
Output is correct |
42 |
Correct |
56 ms |
86072 KB |
Output is correct |
43 |
Correct |
1014 ms |
151632 KB |
Output is correct |
44 |
Correct |
59 ms |
84920 KB |
Output is correct |
45 |
Correct |
1166 ms |
151624 KB |
Output is correct |
46 |
Correct |
48 ms |
86072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
896 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 |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
896 KB |
Output is correct |
18 |
Incorrect |
1 ms |
1152 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |