#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int MAXN = 205;
int N, L;
int X[MAXN], T[MAXN];
lint dist[MAXN][MAXN][2][MAXN];
struct State {
int left;
int right;
int pos_right;
int stamps;
State() {}
State(int l, int r, int p, int s) : left(l), right(r), pos_right(p), stamps(s) {}
bool operator < (const State &o) const {
return stamps < o.stamps;
}
};
int Distance(int a, int b) {
if (a > b) swap(a, b);
return min(X[b] - X[a], X[a] + L - X[b]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
memset(dist, -1, sizeof(dist));
cin >> N >> L;
for (int i = 1; i <= N; i++) {
cin >> X[i];
}
X[N + 1] = L;
for (int i = 1; i <= N; i++) {
cin >> T[i];
}
priority_queue<pair<lint, State>, vector<pair<lint, State>>, greater<pair<lint, State>>> pq;
pq.emplace(0, State(0, N + 1, 0, 0));
dist[0][N + 1][0][0] = 0;
int ans = 0;
while (!pq.empty()) {
int left = pq.top().second.left;
int right = pq.top().second.right;
int pos_right = pq.top().second.pos_right;
int stamps = pq.top().second.stamps;
lint dt = pq.top().first;
pq.pop();
ans = max(ans, stamps);
if (left > right || dist[left][right][pos_right][stamps] != dt) {
continue;
}
int cur = pos_right ? right : left;
if (left + 1 < right) {
lint &nxt = dist[left + 1][right][0][stamps + (dt + Distance(left + 1, cur) <= T[left + 1])];
if (nxt == -1 || nxt > dt + Distance(left + 1, cur)) {
nxt = dt + Distance(left + 1, cur);
pq.emplace(nxt, State(left + 1, right, 0, stamps + (dt + Distance(left + 1, cur) <= T[left + 1])));
}
}
if (left < right - 1) {
lint &nxt = dist[left][right - 1][1][stamps + (dt + Distance(right - 1, cur) <= T[right - 1])];
if (nxt == -1 || nxt > dt + Distance(right - 1, cur)) {
nxt = dt + Distance(right - 1, cur);
pq.emplace(nxt, State(left, right - 1, 1, stamps + (dt + Distance(right - 1, cur) <= T[right - 1])));
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
135160 KB |
Output is correct |
2 |
Correct |
70 ms |
135160 KB |
Output is correct |
3 |
Correct |
70 ms |
135288 KB |
Output is correct |
4 |
Correct |
70 ms |
135288 KB |
Output is correct |
5 |
Correct |
71 ms |
135288 KB |
Output is correct |
6 |
Correct |
75 ms |
135288 KB |
Output is correct |
7 |
Correct |
72 ms |
135288 KB |
Output is correct |
8 |
Correct |
70 ms |
135288 KB |
Output is correct |
9 |
Correct |
76 ms |
135288 KB |
Output is correct |
10 |
Correct |
70 ms |
135160 KB |
Output is correct |
11 |
Correct |
70 ms |
135288 KB |
Output is correct |
12 |
Correct |
77 ms |
135292 KB |
Output is correct |
13 |
Correct |
73 ms |
135288 KB |
Output is correct |
14 |
Correct |
76 ms |
135332 KB |
Output is correct |
15 |
Correct |
70 ms |
135264 KB |
Output is correct |
16 |
Correct |
69 ms |
135160 KB |
Output is correct |
17 |
Correct |
76 ms |
135164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
135160 KB |
Output is correct |
2 |
Correct |
70 ms |
135160 KB |
Output is correct |
3 |
Correct |
70 ms |
135288 KB |
Output is correct |
4 |
Correct |
70 ms |
135288 KB |
Output is correct |
5 |
Correct |
71 ms |
135288 KB |
Output is correct |
6 |
Correct |
75 ms |
135288 KB |
Output is correct |
7 |
Correct |
72 ms |
135288 KB |
Output is correct |
8 |
Correct |
70 ms |
135288 KB |
Output is correct |
9 |
Correct |
76 ms |
135288 KB |
Output is correct |
10 |
Correct |
70 ms |
135160 KB |
Output is correct |
11 |
Correct |
70 ms |
135288 KB |
Output is correct |
12 |
Correct |
77 ms |
135292 KB |
Output is correct |
13 |
Correct |
73 ms |
135288 KB |
Output is correct |
14 |
Correct |
76 ms |
135332 KB |
Output is correct |
15 |
Correct |
70 ms |
135264 KB |
Output is correct |
16 |
Correct |
69 ms |
135160 KB |
Output is correct |
17 |
Correct |
76 ms |
135164 KB |
Output is correct |
18 |
Correct |
77 ms |
135160 KB |
Output is correct |
19 |
Correct |
69 ms |
135288 KB |
Output is correct |
20 |
Correct |
71 ms |
135160 KB |
Output is correct |
21 |
Correct |
70 ms |
135288 KB |
Output is correct |
22 |
Correct |
70 ms |
135160 KB |
Output is correct |
23 |
Correct |
72 ms |
135160 KB |
Output is correct |
24 |
Correct |
69 ms |
135160 KB |
Output is correct |
25 |
Correct |
72 ms |
135288 KB |
Output is correct |
26 |
Correct |
69 ms |
135228 KB |
Output is correct |
27 |
Correct |
70 ms |
135160 KB |
Output is correct |
28 |
Correct |
71 ms |
135160 KB |
Output is correct |
29 |
Correct |
69 ms |
135160 KB |
Output is correct |
30 |
Correct |
76 ms |
135288 KB |
Output is correct |
31 |
Correct |
76 ms |
135160 KB |
Output is correct |
32 |
Correct |
72 ms |
135160 KB |
Output is correct |
33 |
Correct |
69 ms |
135160 KB |
Output is correct |
34 |
Correct |
70 ms |
135416 KB |
Output is correct |
35 |
Correct |
70 ms |
135292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
135160 KB |
Output is correct |
2 |
Correct |
70 ms |
135160 KB |
Output is correct |
3 |
Correct |
70 ms |
135288 KB |
Output is correct |
4 |
Correct |
70 ms |
135288 KB |
Output is correct |
5 |
Correct |
71 ms |
135288 KB |
Output is correct |
6 |
Correct |
75 ms |
135288 KB |
Output is correct |
7 |
Correct |
72 ms |
135288 KB |
Output is correct |
8 |
Correct |
70 ms |
135288 KB |
Output is correct |
9 |
Correct |
76 ms |
135288 KB |
Output is correct |
10 |
Correct |
70 ms |
135160 KB |
Output is correct |
11 |
Correct |
70 ms |
135288 KB |
Output is correct |
12 |
Correct |
77 ms |
135292 KB |
Output is correct |
13 |
Correct |
73 ms |
135288 KB |
Output is correct |
14 |
Correct |
76 ms |
135332 KB |
Output is correct |
15 |
Correct |
70 ms |
135264 KB |
Output is correct |
16 |
Correct |
69 ms |
135160 KB |
Output is correct |
17 |
Correct |
76 ms |
135164 KB |
Output is correct |
18 |
Correct |
804 ms |
141540 KB |
Output is correct |
19 |
Correct |
409 ms |
138472 KB |
Output is correct |
20 |
Correct |
170 ms |
136948 KB |
Output is correct |
21 |
Correct |
338 ms |
138452 KB |
Output is correct |
22 |
Correct |
584 ms |
141540 KB |
Output is correct |
23 |
Correct |
181 ms |
136936 KB |
Output is correct |
24 |
Correct |
96 ms |
136180 KB |
Output is correct |
25 |
Correct |
165 ms |
136944 KB |
Output is correct |
26 |
Correct |
81 ms |
135544 KB |
Output is correct |
27 |
Correct |
198 ms |
136948 KB |
Output is correct |
28 |
Correct |
104 ms |
135740 KB |
Output is correct |
29 |
Correct |
161 ms |
136180 KB |
Output is correct |
30 |
Correct |
102 ms |
136180 KB |
Output is correct |
31 |
Correct |
168 ms |
136180 KB |
Output is correct |
32 |
Correct |
106 ms |
136180 KB |
Output is correct |
33 |
Correct |
150 ms |
136084 KB |
Output is correct |
34 |
Correct |
81 ms |
135544 KB |
Output is correct |
35 |
Correct |
90 ms |
135728 KB |
Output is correct |
36 |
Correct |
83 ms |
135736 KB |
Output is correct |
37 |
Correct |
96 ms |
135736 KB |
Output is correct |
38 |
Correct |
96 ms |
136180 KB |
Output is correct |
39 |
Correct |
117 ms |
135864 KB |
Output is correct |
40 |
Correct |
93 ms |
135736 KB |
Output is correct |
41 |
Correct |
1404 ms |
147672 KB |
Output is correct |
42 |
Correct |
88 ms |
135544 KB |
Output is correct |
43 |
Correct |
1297 ms |
147672 KB |
Output is correct |
44 |
Correct |
90 ms |
135544 KB |
Output is correct |
45 |
Correct |
1352 ms |
147672 KB |
Output is correct |
46 |
Correct |
80 ms |
135544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
135160 KB |
Output is correct |
2 |
Correct |
70 ms |
135160 KB |
Output is correct |
3 |
Correct |
70 ms |
135288 KB |
Output is correct |
4 |
Correct |
70 ms |
135288 KB |
Output is correct |
5 |
Correct |
71 ms |
135288 KB |
Output is correct |
6 |
Correct |
75 ms |
135288 KB |
Output is correct |
7 |
Correct |
72 ms |
135288 KB |
Output is correct |
8 |
Correct |
70 ms |
135288 KB |
Output is correct |
9 |
Correct |
76 ms |
135288 KB |
Output is correct |
10 |
Correct |
70 ms |
135160 KB |
Output is correct |
11 |
Correct |
70 ms |
135288 KB |
Output is correct |
12 |
Correct |
77 ms |
135292 KB |
Output is correct |
13 |
Correct |
73 ms |
135288 KB |
Output is correct |
14 |
Correct |
76 ms |
135332 KB |
Output is correct |
15 |
Correct |
70 ms |
135264 KB |
Output is correct |
16 |
Correct |
69 ms |
135160 KB |
Output is correct |
17 |
Correct |
76 ms |
135164 KB |
Output is correct |
18 |
Correct |
77 ms |
135160 KB |
Output is correct |
19 |
Correct |
69 ms |
135288 KB |
Output is correct |
20 |
Correct |
71 ms |
135160 KB |
Output is correct |
21 |
Correct |
70 ms |
135288 KB |
Output is correct |
22 |
Correct |
70 ms |
135160 KB |
Output is correct |
23 |
Correct |
72 ms |
135160 KB |
Output is correct |
24 |
Correct |
69 ms |
135160 KB |
Output is correct |
25 |
Correct |
72 ms |
135288 KB |
Output is correct |
26 |
Correct |
69 ms |
135228 KB |
Output is correct |
27 |
Correct |
70 ms |
135160 KB |
Output is correct |
28 |
Correct |
71 ms |
135160 KB |
Output is correct |
29 |
Correct |
69 ms |
135160 KB |
Output is correct |
30 |
Correct |
76 ms |
135288 KB |
Output is correct |
31 |
Correct |
76 ms |
135160 KB |
Output is correct |
32 |
Correct |
72 ms |
135160 KB |
Output is correct |
33 |
Correct |
69 ms |
135160 KB |
Output is correct |
34 |
Correct |
70 ms |
135416 KB |
Output is correct |
35 |
Correct |
70 ms |
135292 KB |
Output is correct |
36 |
Correct |
804 ms |
141540 KB |
Output is correct |
37 |
Correct |
409 ms |
138472 KB |
Output is correct |
38 |
Correct |
170 ms |
136948 KB |
Output is correct |
39 |
Correct |
338 ms |
138452 KB |
Output is correct |
40 |
Correct |
584 ms |
141540 KB |
Output is correct |
41 |
Correct |
181 ms |
136936 KB |
Output is correct |
42 |
Correct |
96 ms |
136180 KB |
Output is correct |
43 |
Correct |
165 ms |
136944 KB |
Output is correct |
44 |
Correct |
81 ms |
135544 KB |
Output is correct |
45 |
Correct |
198 ms |
136948 KB |
Output is correct |
46 |
Correct |
104 ms |
135740 KB |
Output is correct |
47 |
Correct |
161 ms |
136180 KB |
Output is correct |
48 |
Correct |
102 ms |
136180 KB |
Output is correct |
49 |
Correct |
168 ms |
136180 KB |
Output is correct |
50 |
Correct |
106 ms |
136180 KB |
Output is correct |
51 |
Correct |
150 ms |
136084 KB |
Output is correct |
52 |
Correct |
81 ms |
135544 KB |
Output is correct |
53 |
Correct |
90 ms |
135728 KB |
Output is correct |
54 |
Correct |
83 ms |
135736 KB |
Output is correct |
55 |
Correct |
96 ms |
135736 KB |
Output is correct |
56 |
Correct |
96 ms |
136180 KB |
Output is correct |
57 |
Correct |
117 ms |
135864 KB |
Output is correct |
58 |
Correct |
93 ms |
135736 KB |
Output is correct |
59 |
Correct |
1404 ms |
147672 KB |
Output is correct |
60 |
Correct |
88 ms |
135544 KB |
Output is correct |
61 |
Correct |
1297 ms |
147672 KB |
Output is correct |
62 |
Correct |
90 ms |
135544 KB |
Output is correct |
63 |
Correct |
1352 ms |
147672 KB |
Output is correct |
64 |
Correct |
80 ms |
135544 KB |
Output is correct |
65 |
Correct |
1157 ms |
147780 KB |
Output is correct |
66 |
Correct |
997 ms |
147688 KB |
Output is correct |
67 |
Correct |
1055 ms |
147928 KB |
Output is correct |
68 |
Correct |
743 ms |
141536 KB |
Output is correct |
69 |
Correct |
1200 ms |
147668 KB |
Output is correct |
70 |
Correct |
1060 ms |
141536 KB |
Output is correct |
71 |
Correct |
801 ms |
147800 KB |
Output is correct |
72 |
Correct |
1190 ms |
147820 KB |
Output is correct |
73 |
Correct |
414 ms |
141412 KB |
Output is correct |
74 |
Correct |
843 ms |
141556 KB |
Output is correct |
75 |
Correct |
774 ms |
147720 KB |
Output is correct |
76 |
Correct |
1414 ms |
141664 KB |
Output is correct |
77 |
Correct |
1084 ms |
147820 KB |
Output is correct |
78 |
Correct |
857 ms |
138472 KB |
Output is correct |
79 |
Correct |
915 ms |
147672 KB |
Output is correct |
80 |
Correct |
1374 ms |
141540 KB |
Output is correct |
81 |
Correct |
697 ms |
147800 KB |
Output is correct |
82 |
Correct |
517 ms |
141568 KB |
Output is correct |
83 |
Correct |
1232 ms |
147676 KB |
Output is correct |
84 |
Correct |
521 ms |
141536 KB |
Output is correct |
85 |
Correct |
551 ms |
141536 KB |
Output is correct |
86 |
Correct |
664 ms |
141536 KB |
Output is correct |
87 |
Correct |
1048 ms |
147800 KB |
Output is correct |
88 |
Execution timed out |
2057 ms |
147672 KB |
Time limit exceeded |
89 |
Halted |
0 ms |
0 KB |
- |