#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 201;
const int INF = 1e17;
int N, L;
int dp[MAX_N][MAX_N][MAX_N];
int X[MAX_N];
int T[MAX_N];
struct Node{
int t;
int cur, other;
int has;
Node(int _t, int _cur, int _other, int _has){
t = _t;
cur = _cur;
other = _other;
has = _has;
}
bool operator<(const Node &b)const{
return t>b.t;
}
};
vector<Node> gen_neig(Node& cur){
int left, right;
left = max(cur.cur, cur.other);
right = min(cur.cur, cur.other);
//cout<<left<<" "<<right<<" "<<cur.t<<" "<<cur.has<<endl;
vector<Node> res;
if(cur.cur == left){
if(left>right){
int new_time = cur.t + ((X[(left+1LL)%L] - X[left] +L)%L);
if(new_time<=T[left]){
res.push_back(Node(new_time, left-1LL, right, cur.has +1LL));
}
else{
res.push_back(Node(new_time, left-1LL, right, cur.has));
}
}
}
if(cur.cur == right){
if(left>right){
int new_time = cur.t + abs(X[right]- X[right+1LL]);
if(new_time<=T[right+1]){
res.push_back(Node(new_time, right+1LL, left, cur.has +1LL));
}
else{
res.push_back(Node(new_time, right+1LL, left, cur.has));
}
}
}
////cout<<"pos L: "<<X[(left+1)%L]<<endl;
res.push_back(Node(cur.t + abs( (L - X[(left+1LL)%L])%L+ X[right]), cur.other, cur.cur, cur.has));
return res;
}
signed main(){
cin>>N>>L;
N++;
X[0] =0LL;
fill(&dp[0][0][0], &dp[MAX_N-1][MAX_N-1][MAX_N-1], INF);
T[0]= -1;
for(int i = 1; i<N; i++){
cin>>X[i];
}
for(int i = 1; i<N; i++){
cin>>T[i];
}
priority_queue<Node> pq;
pq.push(Node(0, 0, N-1, 0));
dp[0][N-1][0] = 0;
while(pq.size()>0){
auto cur = pq.top();
pq.pop();
////cout<<cur.cur<<" "<<cur.other<<" "<<cur.has<<" "<<cur.t<<endl;
if(dp[cur.cur][cur.other][cur.has] == cur.t){
//cout<<"actual"<<endl;
auto neigs = gen_neig(cur);
for(auto v: neigs){
if(dp[v.cur][v.other][v.has]> v.t){
pq.push(v);
dp[v.cur][v.other][v.has] = v.t;
}
}
}
else{
//cout<<dp[cur.cur][cur.other][cur.has]<<endl;
}
}
int best = 0LL;
for(int i = 0; i<N; i++){
for(int k = 0; k<N; k++){
for(int j = 0; j<=N; j++){
if(dp[i][k][j] <INF){
best = max(best, j);
}
}
}
}
cout<<best<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63832 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
12 ms |
63836 KB |
Output is correct |
5 |
Correct |
12 ms |
63832 KB |
Output is correct |
6 |
Correct |
12 ms |
63832 KB |
Output is correct |
7 |
Correct |
12 ms |
63832 KB |
Output is correct |
8 |
Correct |
13 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
13 ms |
64344 KB |
Output is correct |
11 |
Correct |
12 ms |
63832 KB |
Output is correct |
12 |
Correct |
12 ms |
63836 KB |
Output is correct |
13 |
Correct |
12 ms |
63832 KB |
Output is correct |
14 |
Correct |
12 ms |
63832 KB |
Output is correct |
15 |
Correct |
12 ms |
63832 KB |
Output is correct |
16 |
Correct |
12 ms |
63832 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63832 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
12 ms |
63836 KB |
Output is correct |
5 |
Correct |
12 ms |
63832 KB |
Output is correct |
6 |
Correct |
12 ms |
63832 KB |
Output is correct |
7 |
Correct |
12 ms |
63832 KB |
Output is correct |
8 |
Correct |
13 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
13 ms |
64344 KB |
Output is correct |
11 |
Correct |
12 ms |
63832 KB |
Output is correct |
12 |
Correct |
12 ms |
63836 KB |
Output is correct |
13 |
Correct |
12 ms |
63832 KB |
Output is correct |
14 |
Correct |
12 ms |
63832 KB |
Output is correct |
15 |
Correct |
12 ms |
63832 KB |
Output is correct |
16 |
Correct |
12 ms |
63832 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
18 |
Correct |
12 ms |
63836 KB |
Output is correct |
19 |
Correct |
12 ms |
63832 KB |
Output is correct |
20 |
Correct |
12 ms |
63836 KB |
Output is correct |
21 |
Correct |
12 ms |
63836 KB |
Output is correct |
22 |
Correct |
13 ms |
63832 KB |
Output is correct |
23 |
Correct |
12 ms |
63832 KB |
Output is correct |
24 |
Correct |
13 ms |
63888 KB |
Output is correct |
25 |
Correct |
12 ms |
63832 KB |
Output is correct |
26 |
Correct |
12 ms |
63832 KB |
Output is correct |
27 |
Correct |
12 ms |
63832 KB |
Output is correct |
28 |
Correct |
12 ms |
63836 KB |
Output is correct |
29 |
Correct |
12 ms |
63832 KB |
Output is correct |
30 |
Correct |
12 ms |
63832 KB |
Output is correct |
31 |
Correct |
12 ms |
63832 KB |
Output is correct |
32 |
Correct |
12 ms |
63832 KB |
Output is correct |
33 |
Correct |
14 ms |
63832 KB |
Output is correct |
34 |
Correct |
12 ms |
63832 KB |
Output is correct |
35 |
Correct |
13 ms |
64244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63832 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
12 ms |
63836 KB |
Output is correct |
5 |
Correct |
12 ms |
63832 KB |
Output is correct |
6 |
Correct |
12 ms |
63832 KB |
Output is correct |
7 |
Correct |
12 ms |
63832 KB |
Output is correct |
8 |
Correct |
13 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
13 ms |
64344 KB |
Output is correct |
11 |
Correct |
12 ms |
63832 KB |
Output is correct |
12 |
Correct |
12 ms |
63836 KB |
Output is correct |
13 |
Correct |
12 ms |
63832 KB |
Output is correct |
14 |
Correct |
12 ms |
63832 KB |
Output is correct |
15 |
Correct |
12 ms |
63832 KB |
Output is correct |
16 |
Correct |
12 ms |
63832 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
18 |
Correct |
439 ms |
81576 KB |
Output is correct |
19 |
Correct |
197 ms |
73140 KB |
Output is correct |
20 |
Correct |
67 ms |
68544 KB |
Output is correct |
21 |
Correct |
171 ms |
73140 KB |
Output is correct |
22 |
Correct |
280 ms |
80556 KB |
Output is correct |
23 |
Correct |
37 ms |
65988 KB |
Output is correct |
24 |
Correct |
34 ms |
65996 KB |
Output is correct |
25 |
Correct |
38 ms |
65156 KB |
Output is correct |
26 |
Correct |
19 ms |
64468 KB |
Output is correct |
27 |
Correct |
39 ms |
65988 KB |
Output is correct |
28 |
Correct |
30 ms |
65992 KB |
Output is correct |
29 |
Correct |
59 ms |
65992 KB |
Output is correct |
30 |
Correct |
34 ms |
65996 KB |
Output is correct |
31 |
Correct |
59 ms |
66056 KB |
Output is correct |
32 |
Correct |
29 ms |
64976 KB |
Output is correct |
33 |
Correct |
58 ms |
65988 KB |
Output is correct |
34 |
Correct |
19 ms |
64976 KB |
Output is correct |
35 |
Correct |
28 ms |
64468 KB |
Output is correct |
36 |
Correct |
21 ms |
64976 KB |
Output is correct |
37 |
Correct |
27 ms |
64968 KB |
Output is correct |
38 |
Correct |
26 ms |
64968 KB |
Output is correct |
39 |
Correct |
28 ms |
64976 KB |
Output is correct |
40 |
Correct |
25 ms |
64976 KB |
Output is correct |
41 |
Correct |
709 ms |
97044 KB |
Output is correct |
42 |
Correct |
26 ms |
64336 KB |
Output is correct |
43 |
Correct |
763 ms |
98732 KB |
Output is correct |
44 |
Correct |
22 ms |
64344 KB |
Output is correct |
45 |
Correct |
705 ms |
96932 KB |
Output is correct |
46 |
Correct |
23 ms |
64344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
63832 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
12 ms |
63836 KB |
Output is correct |
5 |
Correct |
12 ms |
63832 KB |
Output is correct |
6 |
Correct |
12 ms |
63832 KB |
Output is correct |
7 |
Correct |
12 ms |
63832 KB |
Output is correct |
8 |
Correct |
13 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
13 ms |
64344 KB |
Output is correct |
11 |
Correct |
12 ms |
63832 KB |
Output is correct |
12 |
Correct |
12 ms |
63836 KB |
Output is correct |
13 |
Correct |
12 ms |
63832 KB |
Output is correct |
14 |
Correct |
12 ms |
63832 KB |
Output is correct |
15 |
Correct |
12 ms |
63832 KB |
Output is correct |
16 |
Correct |
12 ms |
63832 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
18 |
Correct |
12 ms |
63836 KB |
Output is correct |
19 |
Correct |
12 ms |
63832 KB |
Output is correct |
20 |
Correct |
12 ms |
63836 KB |
Output is correct |
21 |
Correct |
12 ms |
63836 KB |
Output is correct |
22 |
Correct |
13 ms |
63832 KB |
Output is correct |
23 |
Correct |
12 ms |
63832 KB |
Output is correct |
24 |
Correct |
13 ms |
63888 KB |
Output is correct |
25 |
Correct |
12 ms |
63832 KB |
Output is correct |
26 |
Correct |
12 ms |
63832 KB |
Output is correct |
27 |
Correct |
12 ms |
63832 KB |
Output is correct |
28 |
Correct |
12 ms |
63836 KB |
Output is correct |
29 |
Correct |
12 ms |
63832 KB |
Output is correct |
30 |
Correct |
12 ms |
63832 KB |
Output is correct |
31 |
Correct |
12 ms |
63832 KB |
Output is correct |
32 |
Correct |
12 ms |
63832 KB |
Output is correct |
33 |
Correct |
14 ms |
63832 KB |
Output is correct |
34 |
Correct |
12 ms |
63832 KB |
Output is correct |
35 |
Correct |
13 ms |
64244 KB |
Output is correct |
36 |
Correct |
439 ms |
81576 KB |
Output is correct |
37 |
Correct |
197 ms |
73140 KB |
Output is correct |
38 |
Correct |
67 ms |
68544 KB |
Output is correct |
39 |
Correct |
171 ms |
73140 KB |
Output is correct |
40 |
Correct |
280 ms |
80556 KB |
Output is correct |
41 |
Correct |
37 ms |
65988 KB |
Output is correct |
42 |
Correct |
34 ms |
65996 KB |
Output is correct |
43 |
Correct |
38 ms |
65156 KB |
Output is correct |
44 |
Correct |
19 ms |
64468 KB |
Output is correct |
45 |
Correct |
39 ms |
65988 KB |
Output is correct |
46 |
Correct |
30 ms |
65992 KB |
Output is correct |
47 |
Correct |
59 ms |
65992 KB |
Output is correct |
48 |
Correct |
34 ms |
65996 KB |
Output is correct |
49 |
Correct |
59 ms |
66056 KB |
Output is correct |
50 |
Correct |
29 ms |
64976 KB |
Output is correct |
51 |
Correct |
58 ms |
65988 KB |
Output is correct |
52 |
Correct |
19 ms |
64976 KB |
Output is correct |
53 |
Correct |
28 ms |
64468 KB |
Output is correct |
54 |
Correct |
21 ms |
64976 KB |
Output is correct |
55 |
Correct |
27 ms |
64968 KB |
Output is correct |
56 |
Correct |
26 ms |
64968 KB |
Output is correct |
57 |
Correct |
28 ms |
64976 KB |
Output is correct |
58 |
Correct |
25 ms |
64976 KB |
Output is correct |
59 |
Correct |
709 ms |
97044 KB |
Output is correct |
60 |
Correct |
26 ms |
64336 KB |
Output is correct |
61 |
Correct |
763 ms |
98732 KB |
Output is correct |
62 |
Correct |
22 ms |
64344 KB |
Output is correct |
63 |
Correct |
705 ms |
96932 KB |
Output is correct |
64 |
Correct |
23 ms |
64344 KB |
Output is correct |
65 |
Correct |
937 ms |
98728 KB |
Output is correct |
66 |
Correct |
719 ms |
82092 KB |
Output is correct |
67 |
Correct |
491 ms |
81292 KB |
Output is correct |
68 |
Correct |
483 ms |
81076 KB |
Output is correct |
69 |
Correct |
868 ms |
97956 KB |
Output is correct |
70 |
Correct |
282 ms |
81068 KB |
Output is correct |
71 |
Correct |
736 ms |
98212 KB |
Output is correct |
72 |
Correct |
295 ms |
80684 KB |
Output is correct |
73 |
Correct |
347 ms |
82348 KB |
Output is correct |
74 |
Correct |
253 ms |
72632 KB |
Output is correct |
75 |
Correct |
602 ms |
96812 KB |
Output is correct |
76 |
Correct |
499 ms |
81728 KB |
Output is correct |
77 |
Correct |
1051 ms |
98212 KB |
Output is correct |
78 |
Correct |
281 ms |
72884 KB |
Output is correct |
79 |
Correct |
674 ms |
98300 KB |
Output is correct |
80 |
Correct |
522 ms |
81376 KB |
Output is correct |
81 |
Correct |
589 ms |
97396 KB |
Output is correct |
82 |
Correct |
278 ms |
73908 KB |
Output is correct |
83 |
Correct |
994 ms |
97704 KB |
Output is correct |
84 |
Correct |
287 ms |
73728 KB |
Output is correct |
85 |
Correct |
516 ms |
98700 KB |
Output is correct |
86 |
Correct |
332 ms |
74420 KB |
Output is correct |
87 |
Correct |
675 ms |
97700 KB |
Output is correct |
88 |
Incorrect |
868 ms |
96988 KB |
Output isn't correct |
89 |
Halted |
0 ms |
0 KB |
- |