#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 + X[right+1]- X[right];
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])+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 |
14 ms |
64036 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
14 ms |
63916 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 |
12 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
12 ms |
63832 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 |
63836 KB |
Output is correct |
16 |
Correct |
12 ms |
63836 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
64036 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
14 ms |
63916 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 |
12 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
12 ms |
63832 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 |
63836 KB |
Output is correct |
16 |
Correct |
12 ms |
63836 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
18 |
Correct |
12 ms |
63832 KB |
Output is correct |
19 |
Correct |
12 ms |
63832 KB |
Output is correct |
20 |
Correct |
12 ms |
63840 KB |
Output is correct |
21 |
Correct |
12 ms |
63832 KB |
Output is correct |
22 |
Correct |
12 ms |
63832 KB |
Output is correct |
23 |
Correct |
12 ms |
63832 KB |
Output is correct |
24 |
Correct |
12 ms |
63832 KB |
Output is correct |
25 |
Correct |
12 ms |
63924 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 |
63836 KB |
Output is correct |
30 |
Correct |
12 ms |
63836 KB |
Output is correct |
31 |
Correct |
12 ms |
63832 KB |
Output is correct |
32 |
Correct |
12 ms |
63832 KB |
Output is correct |
33 |
Correct |
12 ms |
63832 KB |
Output is correct |
34 |
Correct |
12 ms |
63832 KB |
Output is correct |
35 |
Correct |
12 ms |
63832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
64036 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
14 ms |
63916 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 |
12 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
12 ms |
63832 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 |
63836 KB |
Output is correct |
16 |
Correct |
12 ms |
63836 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
18 |
Correct |
448 ms |
81072 KB |
Output is correct |
19 |
Correct |
199 ms |
74168 KB |
Output is correct |
20 |
Correct |
68 ms |
68548 KB |
Output is correct |
21 |
Correct |
150 ms |
72884 KB |
Output is correct |
22 |
Correct |
293 ms |
81872 KB |
Output is correct |
23 |
Correct |
37 ms |
66116 KB |
Output is correct |
24 |
Correct |
34 ms |
66200 KB |
Output is correct |
25 |
Correct |
37 ms |
65088 KB |
Output is correct |
26 |
Correct |
20 ms |
64468 KB |
Output is correct |
27 |
Correct |
39 ms |
65996 KB |
Output is correct |
28 |
Correct |
30 ms |
66000 KB |
Output is correct |
29 |
Correct |
61 ms |
65988 KB |
Output is correct |
30 |
Correct |
38 ms |
67276 KB |
Output is correct |
31 |
Correct |
57 ms |
67020 KB |
Output is correct |
32 |
Correct |
29 ms |
64976 KB |
Output is correct |
33 |
Correct |
59 ms |
66056 KB |
Output is correct |
34 |
Correct |
19 ms |
64976 KB |
Output is correct |
35 |
Correct |
24 ms |
64468 KB |
Output is correct |
36 |
Correct |
32 ms |
64968 KB |
Output is correct |
37 |
Correct |
28 ms |
64968 KB |
Output is correct |
38 |
Correct |
27 ms |
65016 KB |
Output is correct |
39 |
Correct |
29 ms |
64976 KB |
Output is correct |
40 |
Correct |
27 ms |
64980 KB |
Output is correct |
41 |
Correct |
800 ms |
98912 KB |
Output is correct |
42 |
Correct |
22 ms |
64344 KB |
Output is correct |
43 |
Correct |
820 ms |
97404 KB |
Output is correct |
44 |
Correct |
22 ms |
64344 KB |
Output is correct |
45 |
Correct |
867 ms |
98648 KB |
Output is correct |
46 |
Correct |
23 ms |
64344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
64036 KB |
Output is correct |
2 |
Correct |
12 ms |
63832 KB |
Output is correct |
3 |
Correct |
12 ms |
63832 KB |
Output is correct |
4 |
Correct |
14 ms |
63916 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 |
12 ms |
63832 KB |
Output is correct |
9 |
Correct |
12 ms |
63832 KB |
Output is correct |
10 |
Correct |
12 ms |
63832 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 |
63836 KB |
Output is correct |
16 |
Correct |
12 ms |
63836 KB |
Output is correct |
17 |
Correct |
12 ms |
63832 KB |
Output is correct |
18 |
Correct |
12 ms |
63832 KB |
Output is correct |
19 |
Correct |
12 ms |
63832 KB |
Output is correct |
20 |
Correct |
12 ms |
63840 KB |
Output is correct |
21 |
Correct |
12 ms |
63832 KB |
Output is correct |
22 |
Correct |
12 ms |
63832 KB |
Output is correct |
23 |
Correct |
12 ms |
63832 KB |
Output is correct |
24 |
Correct |
12 ms |
63832 KB |
Output is correct |
25 |
Correct |
12 ms |
63924 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 |
63836 KB |
Output is correct |
30 |
Correct |
12 ms |
63836 KB |
Output is correct |
31 |
Correct |
12 ms |
63832 KB |
Output is correct |
32 |
Correct |
12 ms |
63832 KB |
Output is correct |
33 |
Correct |
12 ms |
63832 KB |
Output is correct |
34 |
Correct |
12 ms |
63832 KB |
Output is correct |
35 |
Correct |
12 ms |
63832 KB |
Output is correct |
36 |
Correct |
448 ms |
81072 KB |
Output is correct |
37 |
Correct |
199 ms |
74168 KB |
Output is correct |
38 |
Correct |
68 ms |
68548 KB |
Output is correct |
39 |
Correct |
150 ms |
72884 KB |
Output is correct |
40 |
Correct |
293 ms |
81872 KB |
Output is correct |
41 |
Correct |
37 ms |
66116 KB |
Output is correct |
42 |
Correct |
34 ms |
66200 KB |
Output is correct |
43 |
Correct |
37 ms |
65088 KB |
Output is correct |
44 |
Correct |
20 ms |
64468 KB |
Output is correct |
45 |
Correct |
39 ms |
65996 KB |
Output is correct |
46 |
Correct |
30 ms |
66000 KB |
Output is correct |
47 |
Correct |
61 ms |
65988 KB |
Output is correct |
48 |
Correct |
38 ms |
67276 KB |
Output is correct |
49 |
Correct |
57 ms |
67020 KB |
Output is correct |
50 |
Correct |
29 ms |
64976 KB |
Output is correct |
51 |
Correct |
59 ms |
66056 KB |
Output is correct |
52 |
Correct |
19 ms |
64976 KB |
Output is correct |
53 |
Correct |
24 ms |
64468 KB |
Output is correct |
54 |
Correct |
32 ms |
64968 KB |
Output is correct |
55 |
Correct |
28 ms |
64968 KB |
Output is correct |
56 |
Correct |
27 ms |
65016 KB |
Output is correct |
57 |
Correct |
29 ms |
64976 KB |
Output is correct |
58 |
Correct |
27 ms |
64980 KB |
Output is correct |
59 |
Correct |
800 ms |
98912 KB |
Output is correct |
60 |
Correct |
22 ms |
64344 KB |
Output is correct |
61 |
Correct |
820 ms |
97404 KB |
Output is correct |
62 |
Correct |
22 ms |
64344 KB |
Output is correct |
63 |
Correct |
867 ms |
98648 KB |
Output is correct |
64 |
Correct |
23 ms |
64344 KB |
Output is correct |
65 |
Correct |
1000 ms |
98844 KB |
Output is correct |
66 |
Correct |
714 ms |
80808 KB |
Output is correct |
67 |
Correct |
565 ms |
82300 KB |
Output is correct |
68 |
Correct |
516 ms |
81976 KB |
Output is correct |
69 |
Correct |
900 ms |
98152 KB |
Output is correct |
70 |
Correct |
292 ms |
82568 KB |
Output is correct |
71 |
Correct |
701 ms |
98624 KB |
Output is correct |
72 |
Correct |
319 ms |
81628 KB |
Output is correct |
73 |
Correct |
338 ms |
81584 KB |
Output is correct |
74 |
Correct |
247 ms |
72372 KB |
Output is correct |
75 |
Correct |
581 ms |
97188 KB |
Output is correct |
76 |
Correct |
501 ms |
82348 KB |
Output is correct |
77 |
Correct |
968 ms |
97444 KB |
Output is correct |
78 |
Correct |
278 ms |
74200 KB |
Output is correct |
79 |
Correct |
626 ms |
96940 KB |
Output is correct |
80 |
Correct |
527 ms |
80544 KB |
Output is correct |
81 |
Correct |
615 ms |
98176 KB |
Output is correct |
82 |
Correct |
283 ms |
74036 KB |
Output is correct |
83 |
Correct |
963 ms |
97704 KB |
Output is correct |
84 |
Correct |
274 ms |
72884 KB |
Output is correct |
85 |
Correct |
495 ms |
96932 KB |
Output is correct |
86 |
Correct |
323 ms |
72844 KB |
Output is correct |
87 |
Correct |
686 ms |
97516 KB |
Output is correct |
88 |
Incorrect |
898 ms |
98516 KB |
Output isn't correct |
89 |
Halted |
0 ms |
0 KB |
- |