#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using namespace std;
const int nax = 211;
void mini(LL &a, LL b) {
if (a == -1)
a = b;
else
a = min(a, b);
}
int n, L;
int x[nax];
int T[nax];
int best;
LL dp[nax][nax][nax][2];
int main() {
scanf ("%d%d", &n, &L);
rep(i, 1, n) scanf ("%d", x + i);
rep(i, 1, n) scanf ("%d", T + i);
rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) rep(g, 0, 1) dp[i][j][k][g] = -1;
dp[0][0][0][0] = 0;
rep(wynik, 0, n)
rep(l, 0, n)
rep(r, 0, n)
rep(g, 0, 1) {
if (dp[wynik][l][r][g] == -1) continue;
best = max(best, wynik);
if (l == 0 && r == 0) {
int nw = ((L - x[n]) <= T[n]);
dp[nw][1][0][0] = L - x[n];
nw = (x[1] <= T[1]);
dp[nw][0][1][1] = x[1];
continue;
}
if (l + r >= n) continue;
LL lewo = x[n - l + 1] - x[n - l];
LL prawo = x[r + 1] - x[r];
LL czas = dp[wynik][l][r][g];
assert(0 <= czas);
if (g == 0) {
assert(0 < lewo);
int nw = wynik + (czas + lewo <= T[n - l]);
mini(dp[nw][l + 1][r][0], czas + lewo);
LL droga = L - x[n - l + 1] + x[r + 1];
assert(0 < droga);
nw = wynik + (czas + droga <= T[r + 1]);
mini(dp[nw][l][r + 1][1], czas + droga);
}
if (g == 1) {
assert(0 < prawo);
int nw = wynik + (czas + prawo <= T[r + 1]);
mini(dp[nw][l][r + 1][1], czas + prawo);
LL droga = x[r] + L - x[n - l];
assert(0 < droga);
nw = wynik + (czas + droga <= T[n - l]);
mini(dp[nw][l + 1][r][0], czas + droga);
}
}
printf ("%d\n", best);
return 0;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n, &L);
~~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:33:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
rep(i, 1, n) scanf ("%d", x + i);
~~~~~~^~~~~~~~~~~~~
ho_t3.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
rep(i, 1, n) scanf ("%d", T + i);
~~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
6 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
1144 KB |
Output is correct |
30 |
Correct |
5 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1144 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
121 ms |
108024 KB |
Output is correct |
19 |
Correct |
71 ms |
65528 KB |
Output is correct |
20 |
Correct |
34 ms |
34936 KB |
Output is correct |
21 |
Correct |
65 ms |
61816 KB |
Output is correct |
22 |
Correct |
93 ms |
80248 KB |
Output is correct |
23 |
Correct |
34 ms |
29816 KB |
Output is correct |
24 |
Correct |
23 ms |
23288 KB |
Output is correct |
25 |
Correct |
31 ms |
29176 KB |
Output is correct |
26 |
Correct |
12 ms |
11256 KB |
Output is correct |
27 |
Correct |
33 ms |
30456 KB |
Output is correct |
28 |
Correct |
21 ms |
21752 KB |
Output is correct |
29 |
Correct |
32 ms |
31096 KB |
Output is correct |
30 |
Correct |
23 ms |
24440 KB |
Output is correct |
31 |
Correct |
29 ms |
29176 KB |
Output is correct |
32 |
Correct |
16 ms |
15352 KB |
Output is correct |
33 |
Correct |
30 ms |
29176 KB |
Output is correct |
34 |
Correct |
11 ms |
10488 KB |
Output is correct |
35 |
Correct |
26 ms |
28536 KB |
Output is correct |
36 |
Correct |
14 ms |
13560 KB |
Output is correct |
37 |
Correct |
28 ms |
30456 KB |
Output is correct |
38 |
Correct |
17 ms |
16632 KB |
Output is correct |
39 |
Correct |
29 ms |
31736 KB |
Output is correct |
40 |
Correct |
18 ms |
18552 KB |
Output is correct |
41 |
Correct |
171 ms |
133368 KB |
Output is correct |
42 |
Correct |
78 ms |
89720 KB |
Output is correct |
43 |
Correct |
167 ms |
133240 KB |
Output is correct |
44 |
Correct |
75 ms |
88696 KB |
Output is correct |
45 |
Correct |
170 ms |
133220 KB |
Output is correct |
46 |
Correct |
76 ms |
89720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
6 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
1144 KB |
Output is correct |
30 |
Correct |
5 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1144 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
36 |
Correct |
121 ms |
108024 KB |
Output is correct |
37 |
Correct |
71 ms |
65528 KB |
Output is correct |
38 |
Correct |
34 ms |
34936 KB |
Output is correct |
39 |
Correct |
65 ms |
61816 KB |
Output is correct |
40 |
Correct |
93 ms |
80248 KB |
Output is correct |
41 |
Correct |
34 ms |
29816 KB |
Output is correct |
42 |
Correct |
23 ms |
23288 KB |
Output is correct |
43 |
Correct |
31 ms |
29176 KB |
Output is correct |
44 |
Correct |
12 ms |
11256 KB |
Output is correct |
45 |
Correct |
33 ms |
30456 KB |
Output is correct |
46 |
Correct |
21 ms |
21752 KB |
Output is correct |
47 |
Correct |
32 ms |
31096 KB |
Output is correct |
48 |
Correct |
23 ms |
24440 KB |
Output is correct |
49 |
Correct |
29 ms |
29176 KB |
Output is correct |
50 |
Correct |
16 ms |
15352 KB |
Output is correct |
51 |
Correct |
30 ms |
29176 KB |
Output is correct |
52 |
Correct |
11 ms |
10488 KB |
Output is correct |
53 |
Correct |
26 ms |
28536 KB |
Output is correct |
54 |
Correct |
14 ms |
13560 KB |
Output is correct |
55 |
Correct |
28 ms |
30456 KB |
Output is correct |
56 |
Correct |
17 ms |
16632 KB |
Output is correct |
57 |
Correct |
29 ms |
31736 KB |
Output is correct |
58 |
Correct |
18 ms |
18552 KB |
Output is correct |
59 |
Correct |
171 ms |
133368 KB |
Output is correct |
60 |
Correct |
78 ms |
89720 KB |
Output is correct |
61 |
Correct |
167 ms |
133240 KB |
Output is correct |
62 |
Correct |
75 ms |
88696 KB |
Output is correct |
63 |
Correct |
170 ms |
133220 KB |
Output is correct |
64 |
Correct |
76 ms |
89720 KB |
Output is correct |
65 |
Correct |
143 ms |
120312 KB |
Output is correct |
66 |
Correct |
128 ms |
110456 KB |
Output is correct |
67 |
Correct |
124 ms |
105592 KB |
Output is correct |
68 |
Correct |
109 ms |
97784 KB |
Output is correct |
69 |
Correct |
155 ms |
119160 KB |
Output is correct |
70 |
Correct |
148 ms |
114172 KB |
Output is correct |
71 |
Correct |
129 ms |
115320 KB |
Output is correct |
72 |
Correct |
158 ms |
116472 KB |
Output is correct |
73 |
Correct |
111 ms |
108024 KB |
Output is correct |
74 |
Correct |
128 ms |
100984 KB |
Output is correct |
75 |
Correct |
129 ms |
111608 KB |
Output is correct |
76 |
Correct |
168 ms |
128120 KB |
Output is correct |
77 |
Correct |
150 ms |
128120 KB |
Output is correct |
78 |
Correct |
117 ms |
98680 KB |
Output is correct |
79 |
Correct |
117 ms |
102136 KB |
Output is correct |
80 |
Correct |
160 ms |
125432 KB |
Output is correct |
81 |
Correct |
116 ms |
103420 KB |
Output is correct |
82 |
Correct |
113 ms |
109176 KB |
Output is correct |
83 |
Correct |
157 ms |
133240 KB |
Output is correct |
84 |
Correct |
119 ms |
114040 KB |
Output is correct |
85 |
Correct |
132 ms |
124152 KB |
Output is correct |
86 |
Correct |
128 ms |
121484 KB |
Output is correct |
87 |
Correct |
131 ms |
111608 KB |
Output is correct |
88 |
Correct |
185 ms |
134716 KB |
Output is correct |
89 |
Correct |
173 ms |
134520 KB |
Output is correct |
90 |
Correct |
93 ms |
112888 KB |
Output is correct |
91 |
Correct |
185 ms |
134520 KB |
Output is correct |
92 |
Correct |
173 ms |
134648 KB |
Output is correct |
93 |
Correct |
112 ms |
131960 KB |
Output is correct |