#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <bitset>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <algorithm>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <ctime>
#include <chrono>
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
*/
#ifdef LOCAL
#define dbg(x) cout << #x << " : " << x << endl;
#else
#define dbg(x)
#endif
#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a, b) for (int i = a; i < b; i++)
#define fj(a, b) for (int j = a; j < b; j++)
#define fk(a, b) for (int k = a; k < b; k++)
#define fi1(a, b) for (int i = a - 1; i >= b; i--)
#define fj1(a, b) for (int j = a - 1; j >= b; j--)
#define fk1(a, b) for (int k = a - 1; k >= b; k--)
#define fx(x, a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2>inline void mine(T1 &x, const T2 &y) { if (y < x) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, const T2 &y) { if (x < y) x = y; }
ostream& operator << (ostream &out, const vector<int> &b) {
for (auto k : b) out << k << ' ';
return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;
const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const double EPS = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int xa[201];
int xb[201];
int ta[201];
int tb[201];
int dp[201][201][201][2];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, l;
cin >> n >> l;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
xb[i + 1] = x;
xa[n - i] = l - x;
}
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
tb[i + 1] = t;
ta[n - i] = t;
}
for (int a = 0; a <= n; ++a) {
for (int b = 0; b + a <= n; ++b) {
for (int cnt = 0; cnt <= n; ++cnt) {
for (int ep = 0; ep < 2; ++ep) {
dp[a][b][cnt][ep] = BIG;
}
}
}
}
dp[0][0][0][1] = dp[0][0][0][0] = 0;
for (int s = 0; s < n; ++s) {
for (int a = 0; a <= s; ++a) {
int b = s - a;
for (int cnt = 0; cnt <= s; ++cnt) {
//ep = 0 - in a
int t2;
// a + 1
t2 = dp[a][b][cnt][0] + xa[a + 1] - xa[a];
mine(dp[a + 1][b][cnt + (t2 <= ta[a + 1])][0], t2);
// b + 1
t2 = dp[a][b][cnt][0] + xa[a] + xb[b + 1];
mine(dp[a][b + 1][cnt + (t2 <= tb[b + 1])][1], t2);
// ep = 1 - in b
// b + 1
t2 = dp[a][b][cnt][1] + xb[b + 1] - xb[b];
mine(dp[a][b + 1][cnt + (t2 <= tb[b + 1])][1], t2);
// a + 1
t2 = dp[a][b][cnt][1] + xb[b] + xa[a + 1];
mine(dp[a + 1][b][cnt + (t2 <= ta[a + 1])][0], t2);
}
}
}
for (int cnt = n; cnt >= 0; --cnt) {
for (int a = 0; a <= n; ++a) {
for (int b = max(0ll, cnt - a); a + b <= n; ++b) {
for (int ep = 0; ep < 2; ++ep) {
if (dp[a][b][cnt][ep] != BIG) {
cout << cnt << '\n';
exit(0);
}
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
748 KB |
Output is correct |
19 |
Correct |
1 ms |
620 KB |
Output is correct |
20 |
Correct |
1 ms |
620 KB |
Output is correct |
21 |
Correct |
1 ms |
748 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
748 KB |
Output is correct |
24 |
Correct |
1 ms |
748 KB |
Output is correct |
25 |
Correct |
1 ms |
748 KB |
Output is correct |
26 |
Correct |
1 ms |
748 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
748 KB |
Output is correct |
30 |
Correct |
1 ms |
748 KB |
Output is correct |
31 |
Correct |
1 ms |
748 KB |
Output is correct |
32 |
Correct |
1 ms |
748 KB |
Output is correct |
33 |
Correct |
1 ms |
748 KB |
Output is correct |
34 |
Correct |
1 ms |
748 KB |
Output is correct |
35 |
Correct |
1 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
620 KB |
Output is correct |
18 |
Correct |
65 ms |
52460 KB |
Output is correct |
19 |
Correct |
32 ms |
31980 KB |
Output is correct |
20 |
Correct |
18 ms |
17260 KB |
Output is correct |
21 |
Correct |
30 ms |
30188 KB |
Output is correct |
22 |
Correct |
41 ms |
39020 KB |
Output is correct |
23 |
Correct |
13 ms |
14700 KB |
Output is correct |
24 |
Correct |
9 ms |
11628 KB |
Output is correct |
25 |
Correct |
13 ms |
14444 KB |
Output is correct |
26 |
Correct |
4 ms |
5740 KB |
Output is correct |
27 |
Correct |
13 ms |
14956 KB |
Output is correct |
28 |
Correct |
8 ms |
10732 KB |
Output is correct |
29 |
Correct |
13 ms |
15340 KB |
Output is correct |
30 |
Correct |
12 ms |
12140 KB |
Output is correct |
31 |
Correct |
14 ms |
14444 KB |
Output is correct |
32 |
Correct |
7 ms |
7660 KB |
Output is correct |
33 |
Correct |
12 ms |
14444 KB |
Output is correct |
34 |
Correct |
4 ms |
5356 KB |
Output is correct |
35 |
Correct |
12 ms |
14060 KB |
Output is correct |
36 |
Correct |
5 ms |
6892 KB |
Output is correct |
37 |
Correct |
13 ms |
14996 KB |
Output is correct |
38 |
Correct |
6 ms |
8428 KB |
Output is correct |
39 |
Correct |
14 ms |
15596 KB |
Output is correct |
40 |
Correct |
8 ms |
9324 KB |
Output is correct |
41 |
Correct |
73 ms |
64492 KB |
Output is correct |
42 |
Correct |
52 ms |
43628 KB |
Output is correct |
43 |
Correct |
73 ms |
64492 KB |
Output is correct |
44 |
Correct |
57 ms |
43116 KB |
Output is correct |
45 |
Correct |
72 ms |
64492 KB |
Output is correct |
46 |
Correct |
50 ms |
43628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
620 KB |
Output is correct |
9 |
Correct |
1 ms |
620 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
620 KB |
Output is correct |
17 |
Correct |
1 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
748 KB |
Output is correct |
19 |
Correct |
1 ms |
620 KB |
Output is correct |
20 |
Correct |
1 ms |
620 KB |
Output is correct |
21 |
Correct |
1 ms |
748 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
748 KB |
Output is correct |
24 |
Correct |
1 ms |
748 KB |
Output is correct |
25 |
Correct |
1 ms |
748 KB |
Output is correct |
26 |
Correct |
1 ms |
748 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
748 KB |
Output is correct |
30 |
Correct |
1 ms |
748 KB |
Output is correct |
31 |
Correct |
1 ms |
748 KB |
Output is correct |
32 |
Correct |
1 ms |
748 KB |
Output is correct |
33 |
Correct |
1 ms |
748 KB |
Output is correct |
34 |
Correct |
1 ms |
748 KB |
Output is correct |
35 |
Correct |
1 ms |
748 KB |
Output is correct |
36 |
Correct |
65 ms |
52460 KB |
Output is correct |
37 |
Correct |
32 ms |
31980 KB |
Output is correct |
38 |
Correct |
18 ms |
17260 KB |
Output is correct |
39 |
Correct |
30 ms |
30188 KB |
Output is correct |
40 |
Correct |
41 ms |
39020 KB |
Output is correct |
41 |
Correct |
13 ms |
14700 KB |
Output is correct |
42 |
Correct |
9 ms |
11628 KB |
Output is correct |
43 |
Correct |
13 ms |
14444 KB |
Output is correct |
44 |
Correct |
4 ms |
5740 KB |
Output is correct |
45 |
Correct |
13 ms |
14956 KB |
Output is correct |
46 |
Correct |
8 ms |
10732 KB |
Output is correct |
47 |
Correct |
13 ms |
15340 KB |
Output is correct |
48 |
Correct |
12 ms |
12140 KB |
Output is correct |
49 |
Correct |
14 ms |
14444 KB |
Output is correct |
50 |
Correct |
7 ms |
7660 KB |
Output is correct |
51 |
Correct |
12 ms |
14444 KB |
Output is correct |
52 |
Correct |
4 ms |
5356 KB |
Output is correct |
53 |
Correct |
12 ms |
14060 KB |
Output is correct |
54 |
Correct |
5 ms |
6892 KB |
Output is correct |
55 |
Correct |
13 ms |
14996 KB |
Output is correct |
56 |
Correct |
6 ms |
8428 KB |
Output is correct |
57 |
Correct |
14 ms |
15596 KB |
Output is correct |
58 |
Correct |
8 ms |
9324 KB |
Output is correct |
59 |
Correct |
73 ms |
64492 KB |
Output is correct |
60 |
Correct |
52 ms |
43628 KB |
Output is correct |
61 |
Correct |
73 ms |
64492 KB |
Output is correct |
62 |
Correct |
57 ms |
43116 KB |
Output is correct |
63 |
Correct |
72 ms |
64492 KB |
Output is correct |
64 |
Correct |
50 ms |
43628 KB |
Output is correct |
65 |
Correct |
67 ms |
58368 KB |
Output is correct |
66 |
Correct |
64 ms |
53484 KB |
Output is correct |
67 |
Correct |
63 ms |
51308 KB |
Output is correct |
68 |
Correct |
54 ms |
47340 KB |
Output is correct |
69 |
Correct |
66 ms |
57708 KB |
Output is correct |
70 |
Correct |
69 ms |
55276 KB |
Output is correct |
71 |
Correct |
62 ms |
55916 KB |
Output is correct |
72 |
Correct |
64 ms |
56684 KB |
Output is correct |
73 |
Correct |
55 ms |
52332 KB |
Output is correct |
74 |
Correct |
53 ms |
49004 KB |
Output is correct |
75 |
Correct |
60 ms |
54124 KB |
Output is correct |
76 |
Correct |
72 ms |
61932 KB |
Output is correct |
77 |
Correct |
80 ms |
62080 KB |
Output is correct |
78 |
Correct |
51 ms |
47852 KB |
Output is correct |
79 |
Correct |
65 ms |
49516 KB |
Output is correct |
80 |
Correct |
68 ms |
60780 KB |
Output is correct |
81 |
Correct |
56 ms |
50028 KB |
Output is correct |
82 |
Correct |
60 ms |
52972 KB |
Output is correct |
83 |
Correct |
78 ms |
64492 KB |
Output is correct |
84 |
Correct |
64 ms |
55276 KB |
Output is correct |
85 |
Correct |
66 ms |
60140 KB |
Output is correct |
86 |
Correct |
76 ms |
58988 KB |
Output is correct |
87 |
Correct |
64 ms |
54124 KB |
Output is correct |
88 |
Correct |
80 ms |
65132 KB |
Output is correct |
89 |
Correct |
73 ms |
65132 KB |
Output is correct |
90 |
Correct |
79 ms |
54764 KB |
Output is correct |
91 |
Correct |
77 ms |
65132 KB |
Output is correct |
92 |
Correct |
77 ms |
65260 KB |
Output is correct |
93 |
Correct |
80 ms |
63852 KB |
Output is correct |