#include <bits/stdc++.h>
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()
#define ff first
#define se second
#define mp make_pair
using ll = long long;
int mod = (ll)1e9 + 7;
const int INF = 1e9 + 1;
const int N = 210;
const double eps = 1e-7;
const long long inf = 1e18;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
return (x > y ? x = y, 1 : 0);
}
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
int n, L, a[N], d[N];
long long dis, dp[N][N][N][2];
void solve() {
cin >> n >> L;
for(int i = 1;i <= n;++i)
cin >> a[i];
for(int i = 1;i <= n;++i)
cin >> d[i];
++n;
forn(k, n) forn(len, n) forn(i, n) forn(t, 2) dp[i][len][k][t] = inf;
dp[0][0][0][0] = 0;
int ans = 0;
for(int k = 0;k < n;++k) {
for(int len = 0;len < n;++len) {
for(int i = 0;i < n;++i) {
for(int t = 0;t < 2;++t) {
if(dp[i][len][k][t] == inf)continue;
//debug(i, len, k, t);
int cur = (t == 0 ? i : (i + len) % n);
int lf = (i + n - 1) % n;
int rf = (i + len + 1) % n;
dis = min(L-abs(a[cur]-a[lf]), abs(a[cur]-a[lf])) + dp[i][len][k][t];
ckmi(dp[lf][len+1][k+(dis<=d[lf])][0], dis);
dis = min(L-abs(a[cur]-a[rf]), abs(a[cur]-a[rf])) + dp[i][len][k][t];
ckmi(dp[i][len+1][k+(dis<=d[rf])][1], dis);
ckma(ans, k);
//debug(k);
}
}
}
}
cout << ans << '\n';
}
void test_case() {
int t;
cin >> t;
forn(p, t) {
//cout << "Case #" << p + 1 << ": ";
solve();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
584 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
840 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
584 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
840 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
1092 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
1176 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
584 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
840 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
161 ms |
107492 KB |
Output is correct |
19 |
Correct |
86 ms |
65200 KB |
Output is correct |
20 |
Correct |
38 ms |
34772 KB |
Output is correct |
21 |
Correct |
79 ms |
61484 KB |
Output is correct |
22 |
Correct |
125 ms |
79820 KB |
Output is correct |
23 |
Correct |
33 ms |
29624 KB |
Output is correct |
24 |
Correct |
20 ms |
23180 KB |
Output is correct |
25 |
Correct |
30 ms |
29008 KB |
Output is correct |
26 |
Correct |
9 ms |
11092 KB |
Output is correct |
27 |
Correct |
36 ms |
30224 KB |
Output is correct |
28 |
Correct |
23 ms |
21516 KB |
Output is correct |
29 |
Correct |
35 ms |
30804 KB |
Output is correct |
30 |
Correct |
21 ms |
24244 KB |
Output is correct |
31 |
Correct |
31 ms |
28952 KB |
Output is correct |
32 |
Correct |
12 ms |
15148 KB |
Output is correct |
33 |
Correct |
28 ms |
28944 KB |
Output is correct |
34 |
Correct |
8 ms |
10324 KB |
Output is correct |
35 |
Correct |
24 ms |
28324 KB |
Output is correct |
36 |
Correct |
9 ms |
13524 KB |
Output is correct |
37 |
Correct |
26 ms |
30164 KB |
Output is correct |
38 |
Correct |
13 ms |
16596 KB |
Output is correct |
39 |
Correct |
37 ms |
31532 KB |
Output is correct |
40 |
Correct |
15 ms |
18448 KB |
Output is correct |
41 |
Correct |
263 ms |
132684 KB |
Output is correct |
42 |
Correct |
116 ms |
89192 KB |
Output is correct |
43 |
Correct |
246 ms |
132468 KB |
Output is correct |
44 |
Correct |
108 ms |
88136 KB |
Output is correct |
45 |
Correct |
309 ms |
132588 KB |
Output is correct |
46 |
Correct |
103 ms |
89196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
584 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
840 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
852 KB |
Output is correct |
17 |
Correct |
1 ms |
840 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
852 KB |
Output is correct |
21 |
Correct |
1 ms |
980 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
1092 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
980 KB |
Output is correct |
26 |
Correct |
1 ms |
980 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
1176 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
1 ms |
980 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1108 KB |
Output is correct |
34 |
Correct |
1 ms |
1108 KB |
Output is correct |
35 |
Correct |
1 ms |
1108 KB |
Output is correct |
36 |
Correct |
161 ms |
107492 KB |
Output is correct |
37 |
Correct |
86 ms |
65200 KB |
Output is correct |
38 |
Correct |
38 ms |
34772 KB |
Output is correct |
39 |
Correct |
79 ms |
61484 KB |
Output is correct |
40 |
Correct |
125 ms |
79820 KB |
Output is correct |
41 |
Correct |
33 ms |
29624 KB |
Output is correct |
42 |
Correct |
20 ms |
23180 KB |
Output is correct |
43 |
Correct |
30 ms |
29008 KB |
Output is correct |
44 |
Correct |
9 ms |
11092 KB |
Output is correct |
45 |
Correct |
36 ms |
30224 KB |
Output is correct |
46 |
Correct |
23 ms |
21516 KB |
Output is correct |
47 |
Correct |
35 ms |
30804 KB |
Output is correct |
48 |
Correct |
21 ms |
24244 KB |
Output is correct |
49 |
Correct |
31 ms |
28952 KB |
Output is correct |
50 |
Correct |
12 ms |
15148 KB |
Output is correct |
51 |
Correct |
28 ms |
28944 KB |
Output is correct |
52 |
Correct |
8 ms |
10324 KB |
Output is correct |
53 |
Correct |
24 ms |
28324 KB |
Output is correct |
54 |
Correct |
9 ms |
13524 KB |
Output is correct |
55 |
Correct |
26 ms |
30164 KB |
Output is correct |
56 |
Correct |
13 ms |
16596 KB |
Output is correct |
57 |
Correct |
37 ms |
31532 KB |
Output is correct |
58 |
Correct |
15 ms |
18448 KB |
Output is correct |
59 |
Correct |
263 ms |
132684 KB |
Output is correct |
60 |
Correct |
116 ms |
89192 KB |
Output is correct |
61 |
Correct |
246 ms |
132468 KB |
Output is correct |
62 |
Correct |
108 ms |
88136 KB |
Output is correct |
63 |
Correct |
309 ms |
132588 KB |
Output is correct |
64 |
Correct |
103 ms |
89196 KB |
Output is correct |
65 |
Correct |
244 ms |
119708 KB |
Output is correct |
66 |
Correct |
230 ms |
109920 KB |
Output is correct |
67 |
Correct |
186 ms |
105120 KB |
Output is correct |
68 |
Correct |
206 ms |
97060 KB |
Output is correct |
69 |
Correct |
311 ms |
118504 KB |
Output is correct |
70 |
Correct |
215 ms |
113528 KB |
Output is correct |
71 |
Correct |
200 ms |
114668 KB |
Output is correct |
72 |
Correct |
223 ms |
115960 KB |
Output is correct |
73 |
Correct |
157 ms |
107468 KB |
Output is correct |
74 |
Correct |
175 ms |
100380 KB |
Output is correct |
75 |
Correct |
189 ms |
111136 KB |
Output is correct |
76 |
Correct |
285 ms |
127356 KB |
Output is correct |
77 |
Correct |
229 ms |
127364 KB |
Output is correct |
78 |
Correct |
209 ms |
98200 KB |
Output is correct |
79 |
Correct |
162 ms |
101604 KB |
Output is correct |
80 |
Correct |
262 ms |
124860 KB |
Output is correct |
81 |
Correct |
180 ms |
102788 KB |
Output is correct |
82 |
Correct |
163 ms |
108568 KB |
Output is correct |
83 |
Correct |
310 ms |
132592 KB |
Output is correct |
84 |
Correct |
178 ms |
113532 KB |
Output is correct |
85 |
Correct |
204 ms |
123508 KB |
Output is correct |
86 |
Correct |
214 ms |
120924 KB |
Output is correct |
87 |
Correct |
193 ms |
111052 KB |
Output is correct |
88 |
Correct |
299 ms |
133884 KB |
Output is correct |
89 |
Correct |
269 ms |
133900 KB |
Output is correct |
90 |
Correct |
155 ms |
112288 KB |
Output is correct |
91 |
Correct |
305 ms |
133892 KB |
Output is correct |
92 |
Correct |
252 ms |
133920 KB |
Output is correct |
93 |
Correct |
221 ms |
131360 KB |
Output is correct |