#include<bits/stdc++.h>
#define ff first
#define ss second
constexpr int maxn = 200+10;
std::pair<int,int> a[maxn];
int dp[maxn][maxn][maxn][2];
void min_self(int& a, int b) { a = std::min(a, b); }
int main() {
int n, T; scanf("%d %d", &n, &T);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i].ff);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i].ss);
a[0] = {0, -1}; // a origem
++n;
auto prev = [&](int x) {
return (x+n-1)%n;
};
auto next = [&](int x) {
return (x+1)%n;
};
auto dist = [&](int x, int y) {
if(x > y) return y + T - x;
return y - x;
};
memset(dp, 0x3f, sizeof dp);
dp[0][0][0][0] = 0;
for(int sz = 0; sz < n; sz++) {
for(int l = 0; l < n; l++) {
int r = (l+sz)%n;
for(int k = 0; k <= sz; k++) {
if(std::min(dp[l][r][k][0], dp[l][r][k][1]) == 0x3f3f3f3f || l == next(r)) continue;
// printf("%d %d %d (%d %d)\n\n", l, r, k, dp[l][r][k][0], dp[l][r][k][1]);
// eu ligando com o anterior com o ptr na esq do itv
int t = dp[l][r][k][0] + dist(a[prev(l)].first, a[l].first);
min_self(dp[prev(l)][r][k+(t<=a[prev(l)].second)][0], t);
// printf("%d %d\n", t, prev(l));
// eu ligando com o anterior com o ptr na dir do itv
t = dp[l][r][k][1] + dist(a[prev(l)].first, a[r].first);
min_self(dp[prev(l)][r][k+(t<=a[prev(l)].second)][0], t);
// eu ligando com o proximo com o ptr na esq do itv
t = dp[l][r][k][0] + dist(a[l].first, a[next(r)].first);
min_self(dp[l][next(r)][k+(t<=a[next(r)].second)][1], t);
// eu ligando com o proximo com o ptr na dir do itv
t = dp[l][r][k][1] + dist(a[r].first, a[next(r)].first);
min_self(dp[l][next(r)][k+(t<=a[next(r)].second)][1], t);
}
}
}
int ans = 0;
for(int k = 0; k <= n; k++)
for(int l = 0; l <= n; l++)
for(int r = 0; r <= n; r++)
for(int b : {0, 1})
if(dp[l][r][k][b] < 0x3f3f3f3f)
ans = k;
printf("%d\n", ans);
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:15:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
15 | int n, T; scanf("%d %d", &n, &T);
| ~~~~~^~~~~~~~~~~~~~~~~
ho_t3.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
17 | scanf("%d", &a[i].ff);
| ~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
19 | scanf("%d", &a[i].ss);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
72812 KB |
Output is correct |
2 |
Correct |
45 ms |
72812 KB |
Output is correct |
3 |
Correct |
40 ms |
72812 KB |
Output is correct |
4 |
Correct |
39 ms |
72940 KB |
Output is correct |
5 |
Correct |
39 ms |
72812 KB |
Output is correct |
6 |
Correct |
40 ms |
72812 KB |
Output is correct |
7 |
Correct |
40 ms |
72812 KB |
Output is correct |
8 |
Correct |
39 ms |
72812 KB |
Output is correct |
9 |
Correct |
40 ms |
72812 KB |
Output is correct |
10 |
Correct |
40 ms |
72812 KB |
Output is correct |
11 |
Correct |
39 ms |
72812 KB |
Output is correct |
12 |
Correct |
40 ms |
72812 KB |
Output is correct |
13 |
Correct |
40 ms |
72812 KB |
Output is correct |
14 |
Correct |
41 ms |
72812 KB |
Output is correct |
15 |
Correct |
40 ms |
72812 KB |
Output is correct |
16 |
Correct |
39 ms |
72812 KB |
Output is correct |
17 |
Correct |
39 ms |
72812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
72812 KB |
Output is correct |
2 |
Correct |
45 ms |
72812 KB |
Output is correct |
3 |
Correct |
40 ms |
72812 KB |
Output is correct |
4 |
Correct |
39 ms |
72940 KB |
Output is correct |
5 |
Correct |
39 ms |
72812 KB |
Output is correct |
6 |
Correct |
40 ms |
72812 KB |
Output is correct |
7 |
Correct |
40 ms |
72812 KB |
Output is correct |
8 |
Correct |
39 ms |
72812 KB |
Output is correct |
9 |
Correct |
40 ms |
72812 KB |
Output is correct |
10 |
Correct |
40 ms |
72812 KB |
Output is correct |
11 |
Correct |
39 ms |
72812 KB |
Output is correct |
12 |
Correct |
40 ms |
72812 KB |
Output is correct |
13 |
Correct |
40 ms |
72812 KB |
Output is correct |
14 |
Correct |
41 ms |
72812 KB |
Output is correct |
15 |
Correct |
40 ms |
72812 KB |
Output is correct |
16 |
Correct |
39 ms |
72812 KB |
Output is correct |
17 |
Correct |
39 ms |
72812 KB |
Output is correct |
18 |
Correct |
39 ms |
72812 KB |
Output is correct |
19 |
Correct |
41 ms |
72812 KB |
Output is correct |
20 |
Correct |
40 ms |
72812 KB |
Output is correct |
21 |
Correct |
40 ms |
72940 KB |
Output is correct |
22 |
Correct |
46 ms |
72812 KB |
Output is correct |
23 |
Correct |
39 ms |
72812 KB |
Output is correct |
24 |
Correct |
46 ms |
72812 KB |
Output is correct |
25 |
Correct |
41 ms |
72812 KB |
Output is correct |
26 |
Correct |
39 ms |
72812 KB |
Output is correct |
27 |
Correct |
40 ms |
72940 KB |
Output is correct |
28 |
Correct |
39 ms |
72812 KB |
Output is correct |
29 |
Correct |
40 ms |
72812 KB |
Output is correct |
30 |
Correct |
40 ms |
72940 KB |
Output is correct |
31 |
Correct |
40 ms |
72812 KB |
Output is correct |
32 |
Correct |
40 ms |
72812 KB |
Output is correct |
33 |
Correct |
40 ms |
72812 KB |
Output is correct |
34 |
Correct |
40 ms |
72812 KB |
Output is correct |
35 |
Correct |
40 ms |
72812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
72812 KB |
Output is correct |
2 |
Correct |
45 ms |
72812 KB |
Output is correct |
3 |
Correct |
40 ms |
72812 KB |
Output is correct |
4 |
Correct |
39 ms |
72940 KB |
Output is correct |
5 |
Correct |
39 ms |
72812 KB |
Output is correct |
6 |
Correct |
40 ms |
72812 KB |
Output is correct |
7 |
Correct |
40 ms |
72812 KB |
Output is correct |
8 |
Correct |
39 ms |
72812 KB |
Output is correct |
9 |
Correct |
40 ms |
72812 KB |
Output is correct |
10 |
Correct |
40 ms |
72812 KB |
Output is correct |
11 |
Correct |
39 ms |
72812 KB |
Output is correct |
12 |
Correct |
40 ms |
72812 KB |
Output is correct |
13 |
Correct |
40 ms |
72812 KB |
Output is correct |
14 |
Correct |
41 ms |
72812 KB |
Output is correct |
15 |
Correct |
40 ms |
72812 KB |
Output is correct |
16 |
Correct |
39 ms |
72812 KB |
Output is correct |
17 |
Correct |
39 ms |
72812 KB |
Output is correct |
18 |
Correct |
122 ms |
72812 KB |
Output is correct |
19 |
Correct |
80 ms |
72812 KB |
Output is correct |
20 |
Correct |
56 ms |
72940 KB |
Output is correct |
21 |
Correct |
75 ms |
72812 KB |
Output is correct |
22 |
Correct |
98 ms |
72940 KB |
Output is correct |
23 |
Correct |
54 ms |
72812 KB |
Output is correct |
24 |
Correct |
46 ms |
72812 KB |
Output is correct |
25 |
Correct |
55 ms |
72940 KB |
Output is correct |
26 |
Correct |
45 ms |
72812 KB |
Output is correct |
27 |
Correct |
54 ms |
72812 KB |
Output is correct |
28 |
Correct |
47 ms |
72940 KB |
Output is correct |
29 |
Correct |
53 ms |
72812 KB |
Output is correct |
30 |
Correct |
50 ms |
72960 KB |
Output is correct |
31 |
Correct |
52 ms |
72812 KB |
Output is correct |
32 |
Correct |
44 ms |
72812 KB |
Output is correct |
33 |
Correct |
53 ms |
72812 KB |
Output is correct |
34 |
Correct |
41 ms |
72812 KB |
Output is correct |
35 |
Correct |
49 ms |
72812 KB |
Output is correct |
36 |
Correct |
42 ms |
72812 KB |
Output is correct |
37 |
Correct |
49 ms |
72812 KB |
Output is correct |
38 |
Correct |
44 ms |
72812 KB |
Output is correct |
39 |
Correct |
50 ms |
72812 KB |
Output is correct |
40 |
Correct |
44 ms |
72812 KB |
Output is correct |
41 |
Correct |
161 ms |
72812 KB |
Output is correct |
42 |
Correct |
81 ms |
72940 KB |
Output is correct |
43 |
Correct |
162 ms |
72812 KB |
Output is correct |
44 |
Correct |
80 ms |
72940 KB |
Output is correct |
45 |
Correct |
166 ms |
72940 KB |
Output is correct |
46 |
Correct |
80 ms |
72812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
72812 KB |
Output is correct |
2 |
Correct |
45 ms |
72812 KB |
Output is correct |
3 |
Correct |
40 ms |
72812 KB |
Output is correct |
4 |
Correct |
39 ms |
72940 KB |
Output is correct |
5 |
Correct |
39 ms |
72812 KB |
Output is correct |
6 |
Correct |
40 ms |
72812 KB |
Output is correct |
7 |
Correct |
40 ms |
72812 KB |
Output is correct |
8 |
Correct |
39 ms |
72812 KB |
Output is correct |
9 |
Correct |
40 ms |
72812 KB |
Output is correct |
10 |
Correct |
40 ms |
72812 KB |
Output is correct |
11 |
Correct |
39 ms |
72812 KB |
Output is correct |
12 |
Correct |
40 ms |
72812 KB |
Output is correct |
13 |
Correct |
40 ms |
72812 KB |
Output is correct |
14 |
Correct |
41 ms |
72812 KB |
Output is correct |
15 |
Correct |
40 ms |
72812 KB |
Output is correct |
16 |
Correct |
39 ms |
72812 KB |
Output is correct |
17 |
Correct |
39 ms |
72812 KB |
Output is correct |
18 |
Correct |
39 ms |
72812 KB |
Output is correct |
19 |
Correct |
41 ms |
72812 KB |
Output is correct |
20 |
Correct |
40 ms |
72812 KB |
Output is correct |
21 |
Correct |
40 ms |
72940 KB |
Output is correct |
22 |
Correct |
46 ms |
72812 KB |
Output is correct |
23 |
Correct |
39 ms |
72812 KB |
Output is correct |
24 |
Correct |
46 ms |
72812 KB |
Output is correct |
25 |
Correct |
41 ms |
72812 KB |
Output is correct |
26 |
Correct |
39 ms |
72812 KB |
Output is correct |
27 |
Correct |
40 ms |
72940 KB |
Output is correct |
28 |
Correct |
39 ms |
72812 KB |
Output is correct |
29 |
Correct |
40 ms |
72812 KB |
Output is correct |
30 |
Correct |
40 ms |
72940 KB |
Output is correct |
31 |
Correct |
40 ms |
72812 KB |
Output is correct |
32 |
Correct |
40 ms |
72812 KB |
Output is correct |
33 |
Correct |
40 ms |
72812 KB |
Output is correct |
34 |
Correct |
40 ms |
72812 KB |
Output is correct |
35 |
Correct |
40 ms |
72812 KB |
Output is correct |
36 |
Correct |
122 ms |
72812 KB |
Output is correct |
37 |
Correct |
80 ms |
72812 KB |
Output is correct |
38 |
Correct |
56 ms |
72940 KB |
Output is correct |
39 |
Correct |
75 ms |
72812 KB |
Output is correct |
40 |
Correct |
98 ms |
72940 KB |
Output is correct |
41 |
Correct |
54 ms |
72812 KB |
Output is correct |
42 |
Correct |
46 ms |
72812 KB |
Output is correct |
43 |
Correct |
55 ms |
72940 KB |
Output is correct |
44 |
Correct |
45 ms |
72812 KB |
Output is correct |
45 |
Correct |
54 ms |
72812 KB |
Output is correct |
46 |
Correct |
47 ms |
72940 KB |
Output is correct |
47 |
Correct |
53 ms |
72812 KB |
Output is correct |
48 |
Correct |
50 ms |
72960 KB |
Output is correct |
49 |
Correct |
52 ms |
72812 KB |
Output is correct |
50 |
Correct |
44 ms |
72812 KB |
Output is correct |
51 |
Correct |
53 ms |
72812 KB |
Output is correct |
52 |
Correct |
41 ms |
72812 KB |
Output is correct |
53 |
Correct |
49 ms |
72812 KB |
Output is correct |
54 |
Correct |
42 ms |
72812 KB |
Output is correct |
55 |
Correct |
49 ms |
72812 KB |
Output is correct |
56 |
Correct |
44 ms |
72812 KB |
Output is correct |
57 |
Correct |
50 ms |
72812 KB |
Output is correct |
58 |
Correct |
44 ms |
72812 KB |
Output is correct |
59 |
Correct |
161 ms |
72812 KB |
Output is correct |
60 |
Correct |
81 ms |
72940 KB |
Output is correct |
61 |
Correct |
162 ms |
72812 KB |
Output is correct |
62 |
Correct |
80 ms |
72940 KB |
Output is correct |
63 |
Correct |
166 ms |
72940 KB |
Output is correct |
64 |
Correct |
80 ms |
72812 KB |
Output is correct |
65 |
Correct |
111 ms |
72872 KB |
Output is correct |
66 |
Correct |
102 ms |
72812 KB |
Output is correct |
67 |
Correct |
97 ms |
72940 KB |
Output is correct |
68 |
Correct |
88 ms |
72812 KB |
Output is correct |
69 |
Correct |
109 ms |
72812 KB |
Output is correct |
70 |
Correct |
107 ms |
72812 KB |
Output is correct |
71 |
Correct |
99 ms |
72940 KB |
Output is correct |
72 |
Correct |
111 ms |
72812 KB |
Output is correct |
73 |
Correct |
93 ms |
72812 KB |
Output is correct |
74 |
Correct |
96 ms |
72812 KB |
Output is correct |
75 |
Correct |
99 ms |
72812 KB |
Output is correct |
76 |
Correct |
133 ms |
72812 KB |
Output is correct |
77 |
Correct |
117 ms |
72812 KB |
Output is correct |
78 |
Correct |
101 ms |
73000 KB |
Output is correct |
79 |
Correct |
93 ms |
72812 KB |
Output is correct |
80 |
Correct |
130 ms |
72940 KB |
Output is correct |
81 |
Correct |
91 ms |
72812 KB |
Output is correct |
82 |
Correct |
108 ms |
72940 KB |
Output is correct |
83 |
Correct |
124 ms |
72812 KB |
Output is correct |
84 |
Correct |
114 ms |
72940 KB |
Output is correct |
85 |
Correct |
106 ms |
72812 KB |
Output is correct |
86 |
Correct |
126 ms |
72812 KB |
Output is correct |
87 |
Correct |
101 ms |
72940 KB |
Output is correct |
88 |
Correct |
132 ms |
72812 KB |
Output is correct |
89 |
Correct |
120 ms |
72940 KB |
Output is correct |
90 |
Correct |
98 ms |
72812 KB |
Output is correct |
91 |
Correct |
129 ms |
72812 KB |
Output is correct |
92 |
Correct |
125 ms |
72940 KB |
Output is correct |
93 |
Correct |
115 ms |
72908 KB |
Output is correct |