#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())
ll n, L;
ll a[210], T[210];
vector<pll> dp[210][210][3];
ll ans;
ll dist(ll X, ll Y)
{
if(X < Y)
return a[Y] - a[X];
return a[Y] - a[X] + L;
}
bool comp(pll X, pll Y)
{
if(X.fi != Y.fi)
return X.fi < Y.fi;
return X.se > Y.se;
}
int main(void)
{
fastio
cin >> n >> L;
n++;
for(ll i = 2 ; i <= n ; i++)
cin >> a[i];
for(ll i = 2 ; i <= n ; i++)
cin >> T[i];
a[1] = 0, T[1] = INF;
dp[1][1][0].push_back({0, 0});
dp[1][1][1].push_back({0, 0});
for(ll l = 0 ; l < n - 1 ; l++)
{
for(ll i = 1 ; i <= n ; i++)
{
ll j = (i + l - 1) % n + 1;
sort(dp[i][j][0].begin(), dp[i][j][0].end(), comp);
sort(dp[i][j][1].begin(), dp[i][j][1].end(), comp);
for(ll k = 0 ; k < 2 ; k++)
{
vector<pll> tmp;
ll last = -1;
for(auto &o : dp[i][j][k])
{
if(last < o.se)
{
last = o.se;
tmp.push_back(o);
}
}
dp[i][j][k] = tmp;
}
for(auto &k : dp[i][j][0])
{
ll lf = (i - 1 <= 0) ? n : i - 1;
ll tm = k.fi + dist(lf, i);
if(tm <= T[lf])
dp[lf][j][0].push_back({tm, k.se + 1});
else
dp[lf][j][0].push_back({tm, k.se});
ll rg = (j + 1 > n) ? 1 : j + 1;
tm = k.fi + dist(i, rg);
if(tm <= T[rg])
dp[i][rg][1].push_back({tm, k.se + 1});
else
dp[i][rg][1].push_back({tm, k.se});
}
for(auto &k : dp[i][j][1])
{
ll lf = (i - 1 <= 0) ? n : i - 1;
ll tm = k.fi + dist(lf, j);
if(tm <= T[lf])
dp[lf][j][0].push_back({tm, k.se + 1});
else
dp[lf][j][0].push_back({tm, k.se});
ll rg = (j + 1 > n) ? 1 : j + 1;
tm = k.fi + dist(j, rg);
if(tm <= T[rg])
dp[i][rg][1].push_back({tm, k.se + 1});
else
dp[i][rg][1].push_back({tm, k.se});
}
}
}
for(ll i = 1 ; i <= n ; i++)
{
for(ll j = 1 ; j <= n ; j++)
{
for(auto &k : dp[i][j][0])
ans = max(ans, k.se);
for(auto &k : dp[i][j][1])
ans = max(ans, k.se);
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3540 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3428 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3428 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3432 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3436 KB |
Output is correct |
17 |
Correct |
2 ms |
3432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3540 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3428 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3428 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3432 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3436 KB |
Output is correct |
17 |
Correct |
2 ms |
3432 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3436 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3432 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3456 KB |
Output is correct |
27 |
Correct |
2 ms |
3428 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
2 ms |
3432 KB |
Output is correct |
30 |
Correct |
1 ms |
3412 KB |
Output is correct |
31 |
Correct |
2 ms |
3412 KB |
Output is correct |
32 |
Correct |
2 ms |
3412 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
2 ms |
3412 KB |
Output is correct |
35 |
Correct |
2 ms |
3428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3540 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3428 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3428 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3432 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3436 KB |
Output is correct |
17 |
Correct |
2 ms |
3432 KB |
Output is correct |
18 |
Correct |
17 ms |
10272 KB |
Output is correct |
19 |
Correct |
10 ms |
6592 KB |
Output is correct |
20 |
Correct |
6 ms |
5076 KB |
Output is correct |
21 |
Correct |
8 ms |
6356 KB |
Output is correct |
22 |
Correct |
13 ms |
8424 KB |
Output is correct |
23 |
Correct |
6 ms |
5736 KB |
Output is correct |
24 |
Correct |
6 ms |
5716 KB |
Output is correct |
25 |
Correct |
6 ms |
5728 KB |
Output is correct |
26 |
Correct |
3 ms |
3796 KB |
Output is correct |
27 |
Correct |
6 ms |
5864 KB |
Output is correct |
28 |
Correct |
5 ms |
5220 KB |
Output is correct |
29 |
Correct |
5 ms |
4820 KB |
Output is correct |
30 |
Correct |
6 ms |
5972 KB |
Output is correct |
31 |
Correct |
5 ms |
4820 KB |
Output is correct |
32 |
Correct |
4 ms |
4600 KB |
Output is correct |
33 |
Correct |
5 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4180 KB |
Output is correct |
35 |
Correct |
6 ms |
4692 KB |
Output is correct |
36 |
Correct |
4 ms |
4436 KB |
Output is correct |
37 |
Correct |
5 ms |
5076 KB |
Output is correct |
38 |
Correct |
5 ms |
4564 KB |
Output is correct |
39 |
Correct |
4 ms |
4948 KB |
Output is correct |
40 |
Correct |
4 ms |
4820 KB |
Output is correct |
41 |
Correct |
35 ms |
20344 KB |
Output is correct |
42 |
Correct |
5 ms |
4564 KB |
Output is correct |
43 |
Correct |
36 ms |
20344 KB |
Output is correct |
44 |
Correct |
5 ms |
4564 KB |
Output is correct |
45 |
Correct |
34 ms |
19480 KB |
Output is correct |
46 |
Correct |
5 ms |
4564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3540 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
1 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3428 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3428 KB |
Output is correct |
11 |
Correct |
1 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3432 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
3 ms |
3436 KB |
Output is correct |
17 |
Correct |
2 ms |
3432 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3436 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3432 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3456 KB |
Output is correct |
27 |
Correct |
2 ms |
3428 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
2 ms |
3432 KB |
Output is correct |
30 |
Correct |
1 ms |
3412 KB |
Output is correct |
31 |
Correct |
2 ms |
3412 KB |
Output is correct |
32 |
Correct |
2 ms |
3412 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
2 ms |
3412 KB |
Output is correct |
35 |
Correct |
2 ms |
3428 KB |
Output is correct |
36 |
Correct |
17 ms |
10272 KB |
Output is correct |
37 |
Correct |
10 ms |
6592 KB |
Output is correct |
38 |
Correct |
6 ms |
5076 KB |
Output is correct |
39 |
Correct |
8 ms |
6356 KB |
Output is correct |
40 |
Correct |
13 ms |
8424 KB |
Output is correct |
41 |
Correct |
6 ms |
5736 KB |
Output is correct |
42 |
Correct |
6 ms |
5716 KB |
Output is correct |
43 |
Correct |
6 ms |
5728 KB |
Output is correct |
44 |
Correct |
3 ms |
3796 KB |
Output is correct |
45 |
Correct |
6 ms |
5864 KB |
Output is correct |
46 |
Correct |
5 ms |
5220 KB |
Output is correct |
47 |
Correct |
5 ms |
4820 KB |
Output is correct |
48 |
Correct |
6 ms |
5972 KB |
Output is correct |
49 |
Correct |
5 ms |
4820 KB |
Output is correct |
50 |
Correct |
4 ms |
4600 KB |
Output is correct |
51 |
Correct |
5 ms |
4948 KB |
Output is correct |
52 |
Correct |
3 ms |
4180 KB |
Output is correct |
53 |
Correct |
6 ms |
4692 KB |
Output is correct |
54 |
Correct |
4 ms |
4436 KB |
Output is correct |
55 |
Correct |
5 ms |
5076 KB |
Output is correct |
56 |
Correct |
5 ms |
4564 KB |
Output is correct |
57 |
Correct |
4 ms |
4948 KB |
Output is correct |
58 |
Correct |
4 ms |
4820 KB |
Output is correct |
59 |
Correct |
35 ms |
20344 KB |
Output is correct |
60 |
Correct |
5 ms |
4564 KB |
Output is correct |
61 |
Correct |
36 ms |
20344 KB |
Output is correct |
62 |
Correct |
5 ms |
4564 KB |
Output is correct |
63 |
Correct |
34 ms |
19480 KB |
Output is correct |
64 |
Correct |
5 ms |
4564 KB |
Output is correct |
65 |
Correct |
26 ms |
13588 KB |
Output is correct |
66 |
Correct |
27 ms |
12284 KB |
Output is correct |
67 |
Correct |
21 ms |
12756 KB |
Output is correct |
68 |
Correct |
18 ms |
11316 KB |
Output is correct |
69 |
Correct |
22 ms |
13092 KB |
Output is correct |
70 |
Correct |
37 ms |
21716 KB |
Output is correct |
71 |
Correct |
44 ms |
20960 KB |
Output is correct |
72 |
Correct |
33 ms |
18660 KB |
Output is correct |
73 |
Correct |
46 ms |
27460 KB |
Output is correct |
74 |
Correct |
36 ms |
17828 KB |
Output is correct |
75 |
Correct |
33 ms |
19284 KB |
Output is correct |
76 |
Correct |
41 ms |
24012 KB |
Output is correct |
77 |
Correct |
53 ms |
29172 KB |
Output is correct |
78 |
Correct |
25 ms |
14668 KB |
Output is correct |
79 |
Correct |
41 ms |
23772 KB |
Output is correct |
80 |
Correct |
37 ms |
20996 KB |
Output is correct |
81 |
Correct |
34 ms |
20464 KB |
Output is correct |
82 |
Correct |
27 ms |
16204 KB |
Output is correct |
83 |
Correct |
52 ms |
29184 KB |
Output is correct |
84 |
Correct |
27 ms |
15828 KB |
Output is correct |
85 |
Correct |
65 ms |
35316 KB |
Output is correct |
86 |
Correct |
29 ms |
16348 KB |
Output is correct |
87 |
Correct |
55 ms |
28124 KB |
Output is correct |
88 |
Correct |
31 ms |
18444 KB |
Output is correct |
89 |
Correct |
37 ms |
21068 KB |
Output is correct |
90 |
Correct |
6 ms |
4964 KB |
Output is correct |
91 |
Correct |
35 ms |
19124 KB |
Output is correct |
92 |
Correct |
34 ms |
19476 KB |
Output is correct |
93 |
Correct |
7 ms |
5204 KB |
Output is correct |