#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
using namespace std;
#define endl '\n'
#define db double
#define ll __int128
#define int long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;
const int Max = 1e13 + 7, Inf = 1e15 + 7;
void print(bool x) { cout << (x ? "YES" : "NO") << endl; }
string tostring (__int128 x)
{
string ans = "";
while(x > 0)
{
ans += (x % 10 + '0');
x /= 10;
}
reverse(all(ans));
return ans;
}
int dp[205][205][205][2];
void solve()
{
int n, l; cin >> n >> l;
vector <int> v(n+2), t(n+2);
_for(i, n) cin >> v[i+1];
_for(i, n) cin >> t[i+1];
int ans = 0;
_for(i, n+2) _for(j, n+2) _for(k, n+2){
dp[i][j][k][0] = dp[i][j][k][1] = Inf;
}
dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0; v[n+1] = l;
for(int i = 0; i <= n; i++)
{//cerr << endl << "I -> " << i << endl;
for(int j = n+1; j > i+1; j--)
{
for(int k = 0; k <= n; k++)
{
//cerr << (dp[i][j][k][1] > Max ? -1 : dp[i][j][k][1]) << " ";
int a = min(dp[i][j][k][0] + min(abs(v[i+1] - v[i]), v[i] + (l - v[i+1])),
dp[i][j][k][1] + min(abs(v[i+1] - v[j]), v[i+1] + (l - v[j])));
int b = min(dp[i][j][k][1] + min(abs(v[j] - v[j-1]), v[j-1] + (l - v[j])),
dp[i][j][k][0] + min(abs(v[j-1] - v[i]), v[i] + (l - v[j-1])));
/* if(b < 0)
{
cout << "WA: " << v[j-1] - v[j] << endl;
}*/
dp[i+1][j][k + (a <= t[i+1])][0] = min(dp[i+1][j][k + (a <= t[i+1])][0], a);
dp[i][j-1][k + (b <= t[j-1])][1] = min(dp[i][j-1][k + (b <= t[j-1])][1], b);
}//cerr << endl;
}
}
_for(i, n+1) _for(j, n+1) _for(k, n+1)
{
//if(dp[i][j][k] < Inf) cerr << dp[i][j][k]<< endl;
if(dp[i][j][k][0] < Max) ans = max(ans, k);
if(dp[i][j][k][1] < Max) ans = max(ans, k);
}
cout << ans << endl;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int Q = 1; //cin >> Q;
while (Q--)
{
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
6500 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
6500 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
3 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
3 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10776 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 ms |
12636 KB |
Output is correct |
30 |
Correct |
3 ms |
12812 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
3 ms |
12636 KB |
Output is correct |
35 |
Correct |
3 ms |
12636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
6500 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
70 ms |
119640 KB |
Output is correct |
19 |
Correct |
45 ms |
94812 KB |
Output is correct |
20 |
Correct |
26 ms |
68188 KB |
Output is correct |
21 |
Correct |
45 ms |
90716 KB |
Output is correct |
22 |
Correct |
57 ms |
103256 KB |
Output is correct |
23 |
Correct |
22 ms |
64092 KB |
Output is correct |
24 |
Correct |
16 ms |
55900 KB |
Output is correct |
25 |
Correct |
20 ms |
62044 KB |
Output is correct |
26 |
Correct |
10 ms |
39632 KB |
Output is correct |
27 |
Correct |
23 ms |
64092 KB |
Output is correct |
28 |
Correct |
15 ms |
53992 KB |
Output is correct |
29 |
Correct |
22 ms |
64092 KB |
Output is correct |
30 |
Correct |
17 ms |
57948 KB |
Output is correct |
31 |
Correct |
21 ms |
62044 KB |
Output is correct |
32 |
Correct |
12 ms |
45916 KB |
Output is correct |
33 |
Correct |
21 ms |
62044 KB |
Output is correct |
34 |
Correct |
9 ms |
37468 KB |
Output is correct |
35 |
Correct |
22 ms |
62044 KB |
Output is correct |
36 |
Correct |
11 ms |
43692 KB |
Output is correct |
37 |
Correct |
23 ms |
64092 KB |
Output is correct |
38 |
Correct |
13 ms |
47708 KB |
Output is correct |
39 |
Correct |
23 ms |
66140 KB |
Output is correct |
40 |
Correct |
14 ms |
49756 KB |
Output is correct |
41 |
Correct |
85 ms |
133996 KB |
Output is correct |
42 |
Correct |
59 ms |
109376 KB |
Output is correct |
43 |
Correct |
83 ms |
133776 KB |
Output is correct |
44 |
Correct |
56 ms |
109140 KB |
Output is correct |
45 |
Correct |
84 ms |
133972 KB |
Output is correct |
46 |
Correct |
59 ms |
109372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
6500 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
3 ms |
10588 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
3 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
3 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
8540 KB |
Output is correct |
20 |
Correct |
3 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10776 KB |
Output is correct |
22 |
Correct |
2 ms |
8540 KB |
Output is correct |
23 |
Correct |
3 ms |
12636 KB |
Output is correct |
24 |
Correct |
3 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
2 ms |
6492 KB |
Output is correct |
28 |
Correct |
2 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 ms |
12636 KB |
Output is correct |
30 |
Correct |
3 ms |
12812 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
3 ms |
12636 KB |
Output is correct |
35 |
Correct |
3 ms |
12636 KB |
Output is correct |
36 |
Correct |
70 ms |
119640 KB |
Output is correct |
37 |
Correct |
45 ms |
94812 KB |
Output is correct |
38 |
Correct |
26 ms |
68188 KB |
Output is correct |
39 |
Correct |
45 ms |
90716 KB |
Output is correct |
40 |
Correct |
57 ms |
103256 KB |
Output is correct |
41 |
Correct |
22 ms |
64092 KB |
Output is correct |
42 |
Correct |
16 ms |
55900 KB |
Output is correct |
43 |
Correct |
20 ms |
62044 KB |
Output is correct |
44 |
Correct |
10 ms |
39632 KB |
Output is correct |
45 |
Correct |
23 ms |
64092 KB |
Output is correct |
46 |
Correct |
15 ms |
53992 KB |
Output is correct |
47 |
Correct |
22 ms |
64092 KB |
Output is correct |
48 |
Correct |
17 ms |
57948 KB |
Output is correct |
49 |
Correct |
21 ms |
62044 KB |
Output is correct |
50 |
Correct |
12 ms |
45916 KB |
Output is correct |
51 |
Correct |
21 ms |
62044 KB |
Output is correct |
52 |
Correct |
9 ms |
37468 KB |
Output is correct |
53 |
Correct |
22 ms |
62044 KB |
Output is correct |
54 |
Correct |
11 ms |
43692 KB |
Output is correct |
55 |
Correct |
23 ms |
64092 KB |
Output is correct |
56 |
Correct |
13 ms |
47708 KB |
Output is correct |
57 |
Correct |
23 ms |
66140 KB |
Output is correct |
58 |
Correct |
14 ms |
49756 KB |
Output is correct |
59 |
Correct |
85 ms |
133996 KB |
Output is correct |
60 |
Correct |
59 ms |
109376 KB |
Output is correct |
61 |
Correct |
83 ms |
133776 KB |
Output is correct |
62 |
Correct |
56 ms |
109140 KB |
Output is correct |
63 |
Correct |
84 ms |
133972 KB |
Output is correct |
64 |
Correct |
59 ms |
109372 KB |
Output is correct |
65 |
Correct |
78 ms |
127828 KB |
Output is correct |
66 |
Correct |
71 ms |
121692 KB |
Output is correct |
67 |
Correct |
69 ms |
119636 KB |
Output is correct |
68 |
Correct |
65 ms |
115540 KB |
Output is correct |
69 |
Correct |
75 ms |
125780 KB |
Output is correct |
70 |
Correct |
69 ms |
123740 KB |
Output is correct |
71 |
Correct |
70 ms |
123740 KB |
Output is correct |
72 |
Correct |
73 ms |
125796 KB |
Output is correct |
73 |
Correct |
71 ms |
119636 KB |
Output is correct |
74 |
Correct |
66 ms |
115540 KB |
Output is correct |
75 |
Correct |
71 ms |
121692 KB |
Output is correct |
76 |
Correct |
83 ms |
131956 KB |
Output is correct |
77 |
Correct |
83 ms |
131932 KB |
Output is correct |
78 |
Correct |
67 ms |
115548 KB |
Output is correct |
79 |
Correct |
66 ms |
117588 KB |
Output is correct |
80 |
Correct |
84 ms |
129884 KB |
Output is correct |
81 |
Correct |
65 ms |
117448 KB |
Output is correct |
82 |
Correct |
69 ms |
121680 KB |
Output is correct |
83 |
Correct |
83 ms |
133972 KB |
Output is correct |
84 |
Correct |
75 ms |
123732 KB |
Output is correct |
85 |
Correct |
79 ms |
129884 KB |
Output is correct |
86 |
Correct |
79 ms |
127836 KB |
Output is correct |
87 |
Correct |
70 ms |
121692 KB |
Output is correct |
88 |
Correct |
84 ms |
133972 KB |
Output is correct |
89 |
Correct |
89 ms |
134004 KB |
Output is correct |
90 |
Correct |
73 ms |
123732 KB |
Output is correct |
91 |
Correct |
85 ms |
134228 KB |
Output is correct |
92 |
Correct |
84 ms |
133980 KB |
Output is correct |
93 |
Correct |
81 ms |
133972 KB |
Output is correct |