#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
void usaco()
{
freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
// freopen("problem.out", "w", stdout);
}
int main() {
// usaco();
int n;
lli l;
scd(n);
sclld(l);
vector<lli> vec(n+1), tim(n+1);
frange(i, n) {
sclld(vec[i+1]);
}
frange(i, n) {
sclld(tim[i+1]);
}
vector<vector<vll>> dp1(n+1, vector<vll>(n+1, vll(n+1, 2e18+5))), dp2(n+1, vector<vll>(n+1, vll(n+1, 2e18+5)));
dp1[0][0][0] = dp2[0][0][0] = 0;
forr(le, 1, n+1) {
forr(j, 0, n+1) {
int k = (j + le) % (n+1);
int i = 0;
dp1[j][k][i] = min(dp1[(j+1)%(n+1)][k][i] + (vec[(j+1) % (n+1)] - vec[j] + l) % l, dp2[(j+1) % (n+1)][k][i] + (vec[k] + l - vec[j]) % l);
dp2[j][k][i] = min(dp1[j][(k-1+n+1)%(n+1)][i] + (l - vec[j] + vec[k]) % l, dp2[j][(k-1+n+1)%(n+1)][i] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]));
}
}
forr(i, 1, n+1) {
forr(le, 1, n+1) {
forr(j, 0, n+1) {
int k = (j + le) % (n+1);
dp1[j][k][i] = min(dp1[(j+1)%(n+1)][k][i] + (vec[(j+1) % (n+1)] - vec[j] + l) % l, dp2[(j+1) % (n+1)][k][i] + (vec[k] + l - vec[j]) % l);
if(dp1[(j+1)%(n+1)][k][i-1] + (vec[(j+1) % (n+1)] - vec[j] + l) % l <= tim[j]) {
dp1[j][k][i] = min(dp1[j][k][i], dp1[(j+1)%(n+1)][k][i-1] + (vec[(j+1) % (n+1)] - vec[j] + l) % l);
}
if(dp2[(j+1) % (n+1)][k][i-1] + (vec[k] + l - vec[j]) % l <= tim[j]) {
dp1[j][k][i] = min(dp1[j][k][i], dp2[(j+1) % (n+1)][k][i-1] + (vec[k] + l - vec[j]) % l);
}
dp2[j][k][i] = min(dp1[j][(k-1+n+1)%(n+1)][i] + (l - vec[j] + vec[k]) % l, dp2[j][(k-1+n+1)%(n+1)][i] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l);
if(dp1[j][(k-1+n+1)%(n+1)][i-1] + (l - vec[j] + vec[k]) % l <= tim[k]) {
dp2[j][k][i] = min(dp2[j][k][i], dp1[j][(k-1+n+1)%(n+1)][i-1] + (l - vec[j] + vec[k]) % l);
}
if(dp2[j][(k-1+n+1)%(n+1)][i-1] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l <= tim[k]) {
dp2[j][k][i] = min(dp2[j][k][i], dp2[j][(k-1+n+1)%(n+1)][i-1] + (vec[k] + l - vec[(k-1+n+1)%(n+1)]) % l);
}
}
}
}
for(int v=n; v>= 0; v--) {
frange(i, n+1) {
frange(j, n+1) {
if(dp1[i][j][v] < 2e18+5 || dp2[i][j][v] < 2e18+5) {
printf("%d\n", v);
return 0;
}
}
}
}
}
Compilation message
ho_t3.cpp: In function 'void usaco()':
ho_t3.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
5 | #define scd(t) scanf("%d", &t)
| ~~~~~^~~~~~~~~~
ho_t3.cpp:38:5: note: in expansion of macro 'scd'
38 | scd(n);
| ^~~
ho_t3.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(t) scanf("%lld", &t)
| ~~~~~^~~~~~~~~~~~
ho_t3.cpp:39:5: note: in expansion of macro 'sclld'
39 | sclld(l);
| ^~~~~
ho_t3.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(t) scanf("%lld", &t)
| ~~~~~^~~~~~~~~~~~
ho_t3.cpp:42:9: note: in expansion of macro 'sclld'
42 | sclld(vec[i+1]);
| ^~~~~
ho_t3.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
6 | #define sclld(t) scanf("%lld", &t)
| ~~~~~^~~~~~~~~~~~
ho_t3.cpp:45:9: note: in expansion of macro 'sclld'
45 | sclld(tim[i+1]);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
376 ms |
94528 KB |
Output is correct |
19 |
Correct |
156 ms |
45076 KB |
Output is correct |
20 |
Correct |
63 ms |
17936 KB |
Output is correct |
21 |
Correct |
148 ms |
41556 KB |
Output is correct |
22 |
Correct |
210 ms |
60268 KB |
Output is correct |
23 |
Correct |
46 ms |
14184 KB |
Output is correct |
24 |
Correct |
33 ms |
9820 KB |
Output is correct |
25 |
Correct |
46 ms |
13652 KB |
Output is correct |
26 |
Correct |
11 ms |
3560 KB |
Output is correct |
27 |
Correct |
47 ms |
14424 KB |
Output is correct |
28 |
Correct |
28 ms |
8792 KB |
Output is correct |
29 |
Correct |
50 ms |
14940 KB |
Output is correct |
30 |
Correct |
35 ms |
10548 KB |
Output is correct |
31 |
Correct |
45 ms |
13404 KB |
Output is correct |
32 |
Correct |
18 ms |
5720 KB |
Output is correct |
33 |
Correct |
45 ms |
13404 KB |
Output is correct |
34 |
Correct |
9 ms |
3160 KB |
Output is correct |
35 |
Correct |
44 ms |
13148 KB |
Output is correct |
36 |
Correct |
15 ms |
4692 KB |
Output is correct |
37 |
Correct |
51 ms |
14428 KB |
Output is correct |
38 |
Correct |
21 ms |
5976 KB |
Output is correct |
39 |
Correct |
53 ms |
15192 KB |
Output is correct |
40 |
Correct |
24 ms |
7004 KB |
Output is correct |
41 |
Correct |
503 ms |
129120 KB |
Output is correct |
42 |
Correct |
276 ms |
71760 KB |
Output is correct |
43 |
Correct |
508 ms |
129120 KB |
Output is correct |
44 |
Correct |
259 ms |
69976 KB |
Output is correct |
45 |
Correct |
491 ms |
129104 KB |
Output is correct |
46 |
Correct |
272 ms |
71760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
376 ms |
94528 KB |
Output is correct |
37 |
Correct |
156 ms |
45076 KB |
Output is correct |
38 |
Correct |
63 ms |
17936 KB |
Output is correct |
39 |
Correct |
148 ms |
41556 KB |
Output is correct |
40 |
Correct |
210 ms |
60268 KB |
Output is correct |
41 |
Correct |
46 ms |
14184 KB |
Output is correct |
42 |
Correct |
33 ms |
9820 KB |
Output is correct |
43 |
Correct |
46 ms |
13652 KB |
Output is correct |
44 |
Correct |
11 ms |
3560 KB |
Output is correct |
45 |
Correct |
47 ms |
14424 KB |
Output is correct |
46 |
Correct |
28 ms |
8792 KB |
Output is correct |
47 |
Correct |
50 ms |
14940 KB |
Output is correct |
48 |
Correct |
35 ms |
10548 KB |
Output is correct |
49 |
Correct |
45 ms |
13404 KB |
Output is correct |
50 |
Correct |
18 ms |
5720 KB |
Output is correct |
51 |
Correct |
45 ms |
13404 KB |
Output is correct |
52 |
Correct |
9 ms |
3160 KB |
Output is correct |
53 |
Correct |
44 ms |
13148 KB |
Output is correct |
54 |
Correct |
15 ms |
4692 KB |
Output is correct |
55 |
Correct |
51 ms |
14428 KB |
Output is correct |
56 |
Correct |
21 ms |
5976 KB |
Output is correct |
57 |
Correct |
53 ms |
15192 KB |
Output is correct |
58 |
Correct |
24 ms |
7004 KB |
Output is correct |
59 |
Correct |
503 ms |
129120 KB |
Output is correct |
60 |
Correct |
276 ms |
71760 KB |
Output is correct |
61 |
Correct |
508 ms |
129120 KB |
Output is correct |
62 |
Correct |
259 ms |
69976 KB |
Output is correct |
63 |
Correct |
491 ms |
129104 KB |
Output is correct |
64 |
Correct |
272 ms |
71760 KB |
Output is correct |
65 |
Correct |
436 ms |
110888 KB |
Output is correct |
66 |
Correct |
363 ms |
97688 KB |
Output is correct |
67 |
Correct |
382 ms |
91452 KB |
Output is correct |
68 |
Correct |
289 ms |
80772 KB |
Output is correct |
69 |
Correct |
412 ms |
108644 KB |
Output is correct |
70 |
Correct |
362 ms |
101920 KB |
Output is correct |
71 |
Correct |
414 ms |
104016 KB |
Output is correct |
72 |
Correct |
373 ms |
105268 KB |
Output is correct |
73 |
Correct |
355 ms |
94292 KB |
Output is correct |
74 |
Correct |
298 ms |
85336 KB |
Output is correct |
75 |
Correct |
362 ms |
98728 KB |
Output is correct |
76 |
Correct |
467 ms |
121424 KB |
Output is correct |
77 |
Correct |
494 ms |
121624 KB |
Output is correct |
78 |
Correct |
287 ms |
82524 KB |
Output is correct |
79 |
Correct |
321 ms |
86608 KB |
Output is correct |
80 |
Correct |
443 ms |
117840 KB |
Output is correct |
81 |
Correct |
323 ms |
88456 KB |
Output is correct |
82 |
Correct |
352 ms |
95568 KB |
Output is correct |
83 |
Correct |
494 ms |
129364 KB |
Output is correct |
84 |
Correct |
404 ms |
101712 KB |
Output is correct |
85 |
Incorrect |
490 ms |
115796 KB |
Output isn't correct |
86 |
Halted |
0 ms |
0 KB |
- |