//Never stop trying
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
#define int ll
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<str> vs;
typedef vector<ld> vd;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int memo[201][201][2][201];
//minimum time to visit first i CW and first j CCW
//and be at side (0,CW/1,CCW) and collect n stamps
int nbCW[202],nbCCW[202],distCW[202],distCCW[202],TCW[202],TCCW[202];
int solve(int i, int j, int side, int n){
//Base cases
if(i==0 && j==0){
if(n==0) return 0;
return INF;
}
if(i==0 && side==0){
if(nbCW[j]>=n) return distCW[j]*2;
return INF;
}
if(j==0 && side==1){
if(nbCCW[i]>=n) return distCCW[i]*2;
return INF;
}
if(memo[i][j][side][n]!=-1) return memo[i][j][side][n];
int ans=INF;
//Transitions
if(side==1){ //CW side
assert(j);
ckmin(ans, solve(i,j-1,side,n) + distCW[j]-distCW[j-1]);
ckmin(ans, solve(i,j-1,1-side,n) + distCCW[i]+distCW[j]);
if(n){
int x=solve(i,j-1,side,n-1) + distCW[j]-distCW[j-1];
if(x<=TCW[j]) ckmin(ans,x);
x=solve(i,j-1,1-side,n-1) + distCCW[i]+distCW[j];
if(x<=TCW[j]) ckmin(ans,x);
}
}
else{
assert(i);
ckmin(ans, solve(i-1,j,side,n) + distCCW[i]-distCCW[i-1]);
ckmin(ans, solve(i-1,j,1-side,n) + distCCW[i]+distCW[j]);
if(n){
int x=solve(i-1,j,side,n-1) + distCCW[i]-distCCW[i-1];
if(x<=TCCW[i]) ckmin(ans,x);
x=solve(i-1,j,1-side,n-1) + distCCW[i]+distCW[j];
if(x<=TCCW[i]) ckmin(ans,x);
}
}
return memo[i][j][side][n]=ans;
}
int32_t main() {
boost; IO();
memset(memo,-1,sizeof(memo));
int N,L; cin>>N>>L;
vi X(N),T(N);
FOR(i,0,N) cin>>X[i];
FOR(i,0,N) cin>>T[i];
FOR(i,0,N) TCW[i+1]=T[i];
reverse(all(T));
FOR(i,0,N) TCCW[i+1]=T[i];
//FOR(i,1,N+1) cout << TCCW[i] << ' '; cout << endl;
vi v;
v.assign(all(X));
FOR(i,0,N){
distCW[i+1]=v[i];
}
distCW[0]=0;
v.assign(all(X)); reverse(all(v)); FOR(i,0,N) v[i]=L-v[i];
FOR(i,0,N){
distCCW[i+1]=v[i];
}
distCCW[0]=0;
//FOR(i,1,N+1) cout << distCW[i] << ' '; cout << endl;
int nb=0;
FOR(i,1,N+1){
int x=distCW[i];
if(TCW[i]>=x) nb++;
nbCW[i]=nb;
}
nb=0;
FOR(i,1,N+1){
int x=distCCW[i];
if(TCCW[i]>=x) nb++;
nbCCW[i]=nb;
}
//FOR(i,1,N+1) cout << nbCW[i] << ' '; cout << endl;
int ans=0;
FOR(i,0,N+1) FOR(j,0,N-i+1) FOR(n,1,N+1){
assert(i+j<=N);
int x=min(solve(i,j,0,n),solve(i,j,1,n));
if(x<INF) ckmax(ans,n);
}
cout << ans << endl;
return 0;
}
/* Careful!!!
.Array bounds
.Infinite loops
.Uninitialized variables / empty containers
.Multisets are shit
Some insights:
.Binary search
.Graph representation
.Write brute force code
.Change your approach
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
127460 KB |
Output is correct |
2 |
Correct |
59 ms |
127460 KB |
Output is correct |
3 |
Correct |
60 ms |
127460 KB |
Output is correct |
4 |
Correct |
65 ms |
127528 KB |
Output is correct |
5 |
Correct |
59 ms |
127464 KB |
Output is correct |
6 |
Correct |
60 ms |
127460 KB |
Output is correct |
7 |
Correct |
59 ms |
127460 KB |
Output is correct |
8 |
Correct |
62 ms |
127460 KB |
Output is correct |
9 |
Correct |
60 ms |
127460 KB |
Output is correct |
10 |
Correct |
61 ms |
127460 KB |
Output is correct |
11 |
Correct |
59 ms |
127460 KB |
Output is correct |
12 |
Correct |
60 ms |
127460 KB |
Output is correct |
13 |
Correct |
59 ms |
127524 KB |
Output is correct |
14 |
Correct |
59 ms |
127460 KB |
Output is correct |
15 |
Correct |
69 ms |
127460 KB |
Output is correct |
16 |
Correct |
59 ms |
127424 KB |
Output is correct |
17 |
Correct |
69 ms |
127460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
127460 KB |
Output is correct |
2 |
Correct |
59 ms |
127460 KB |
Output is correct |
3 |
Correct |
60 ms |
127460 KB |
Output is correct |
4 |
Correct |
65 ms |
127528 KB |
Output is correct |
5 |
Correct |
59 ms |
127464 KB |
Output is correct |
6 |
Correct |
60 ms |
127460 KB |
Output is correct |
7 |
Correct |
59 ms |
127460 KB |
Output is correct |
8 |
Correct |
62 ms |
127460 KB |
Output is correct |
9 |
Correct |
60 ms |
127460 KB |
Output is correct |
10 |
Correct |
61 ms |
127460 KB |
Output is correct |
11 |
Correct |
59 ms |
127460 KB |
Output is correct |
12 |
Correct |
60 ms |
127460 KB |
Output is correct |
13 |
Correct |
59 ms |
127524 KB |
Output is correct |
14 |
Correct |
59 ms |
127460 KB |
Output is correct |
15 |
Correct |
69 ms |
127460 KB |
Output is correct |
16 |
Correct |
59 ms |
127424 KB |
Output is correct |
17 |
Correct |
69 ms |
127460 KB |
Output is correct |
18 |
Correct |
61 ms |
127460 KB |
Output is correct |
19 |
Correct |
59 ms |
127436 KB |
Output is correct |
20 |
Correct |
62 ms |
127460 KB |
Output is correct |
21 |
Correct |
62 ms |
127464 KB |
Output is correct |
22 |
Correct |
63 ms |
127460 KB |
Output is correct |
23 |
Correct |
63 ms |
127460 KB |
Output is correct |
24 |
Correct |
60 ms |
127460 KB |
Output is correct |
25 |
Correct |
61 ms |
127460 KB |
Output is correct |
26 |
Correct |
63 ms |
127460 KB |
Output is correct |
27 |
Correct |
61 ms |
127512 KB |
Output is correct |
28 |
Correct |
60 ms |
127460 KB |
Output is correct |
29 |
Correct |
60 ms |
127460 KB |
Output is correct |
30 |
Correct |
63 ms |
127496 KB |
Output is correct |
31 |
Correct |
62 ms |
127460 KB |
Output is correct |
32 |
Correct |
66 ms |
127460 KB |
Output is correct |
33 |
Correct |
60 ms |
127460 KB |
Output is correct |
34 |
Correct |
66 ms |
127560 KB |
Output is correct |
35 |
Correct |
63 ms |
127456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
127460 KB |
Output is correct |
2 |
Correct |
59 ms |
127460 KB |
Output is correct |
3 |
Correct |
60 ms |
127460 KB |
Output is correct |
4 |
Correct |
65 ms |
127528 KB |
Output is correct |
5 |
Correct |
59 ms |
127464 KB |
Output is correct |
6 |
Correct |
60 ms |
127460 KB |
Output is correct |
7 |
Correct |
59 ms |
127460 KB |
Output is correct |
8 |
Correct |
62 ms |
127460 KB |
Output is correct |
9 |
Correct |
60 ms |
127460 KB |
Output is correct |
10 |
Correct |
61 ms |
127460 KB |
Output is correct |
11 |
Correct |
59 ms |
127460 KB |
Output is correct |
12 |
Correct |
60 ms |
127460 KB |
Output is correct |
13 |
Correct |
59 ms |
127524 KB |
Output is correct |
14 |
Correct |
59 ms |
127460 KB |
Output is correct |
15 |
Correct |
69 ms |
127460 KB |
Output is correct |
16 |
Correct |
59 ms |
127424 KB |
Output is correct |
17 |
Correct |
69 ms |
127460 KB |
Output is correct |
18 |
Correct |
262 ms |
127624 KB |
Output is correct |
19 |
Correct |
171 ms |
127480 KB |
Output is correct |
20 |
Correct |
99 ms |
127536 KB |
Output is correct |
21 |
Correct |
157 ms |
127536 KB |
Output is correct |
22 |
Correct |
192 ms |
127588 KB |
Output is correct |
23 |
Correct |
93 ms |
127460 KB |
Output is correct |
24 |
Correct |
81 ms |
127460 KB |
Output is correct |
25 |
Correct |
91 ms |
127460 KB |
Output is correct |
26 |
Correct |
66 ms |
127460 KB |
Output is correct |
27 |
Correct |
91 ms |
127588 KB |
Output is correct |
28 |
Correct |
77 ms |
127456 KB |
Output is correct |
29 |
Correct |
90 ms |
127460 KB |
Output is correct |
30 |
Correct |
81 ms |
127460 KB |
Output is correct |
31 |
Correct |
93 ms |
127588 KB |
Output is correct |
32 |
Correct |
72 ms |
127460 KB |
Output is correct |
33 |
Correct |
88 ms |
127588 KB |
Output is correct |
34 |
Correct |
66 ms |
127460 KB |
Output is correct |
35 |
Correct |
89 ms |
127460 KB |
Output is correct |
36 |
Correct |
70 ms |
127460 KB |
Output is correct |
37 |
Correct |
92 ms |
127460 KB |
Output is correct |
38 |
Correct |
73 ms |
127460 KB |
Output is correct |
39 |
Correct |
92 ms |
127460 KB |
Output is correct |
40 |
Correct |
75 ms |
127460 KB |
Output is correct |
41 |
Correct |
333 ms |
127460 KB |
Output is correct |
42 |
Correct |
209 ms |
127460 KB |
Output is correct |
43 |
Correct |
331 ms |
127588 KB |
Output is correct |
44 |
Correct |
211 ms |
127588 KB |
Output is correct |
45 |
Correct |
386 ms |
127464 KB |
Output is correct |
46 |
Correct |
209 ms |
127588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
127460 KB |
Output is correct |
2 |
Correct |
59 ms |
127460 KB |
Output is correct |
3 |
Correct |
60 ms |
127460 KB |
Output is correct |
4 |
Correct |
65 ms |
127528 KB |
Output is correct |
5 |
Correct |
59 ms |
127464 KB |
Output is correct |
6 |
Correct |
60 ms |
127460 KB |
Output is correct |
7 |
Correct |
59 ms |
127460 KB |
Output is correct |
8 |
Correct |
62 ms |
127460 KB |
Output is correct |
9 |
Correct |
60 ms |
127460 KB |
Output is correct |
10 |
Correct |
61 ms |
127460 KB |
Output is correct |
11 |
Correct |
59 ms |
127460 KB |
Output is correct |
12 |
Correct |
60 ms |
127460 KB |
Output is correct |
13 |
Correct |
59 ms |
127524 KB |
Output is correct |
14 |
Correct |
59 ms |
127460 KB |
Output is correct |
15 |
Correct |
69 ms |
127460 KB |
Output is correct |
16 |
Correct |
59 ms |
127424 KB |
Output is correct |
17 |
Correct |
69 ms |
127460 KB |
Output is correct |
18 |
Correct |
61 ms |
127460 KB |
Output is correct |
19 |
Correct |
59 ms |
127436 KB |
Output is correct |
20 |
Correct |
62 ms |
127460 KB |
Output is correct |
21 |
Correct |
62 ms |
127464 KB |
Output is correct |
22 |
Correct |
63 ms |
127460 KB |
Output is correct |
23 |
Correct |
63 ms |
127460 KB |
Output is correct |
24 |
Correct |
60 ms |
127460 KB |
Output is correct |
25 |
Correct |
61 ms |
127460 KB |
Output is correct |
26 |
Correct |
63 ms |
127460 KB |
Output is correct |
27 |
Correct |
61 ms |
127512 KB |
Output is correct |
28 |
Correct |
60 ms |
127460 KB |
Output is correct |
29 |
Correct |
60 ms |
127460 KB |
Output is correct |
30 |
Correct |
63 ms |
127496 KB |
Output is correct |
31 |
Correct |
62 ms |
127460 KB |
Output is correct |
32 |
Correct |
66 ms |
127460 KB |
Output is correct |
33 |
Correct |
60 ms |
127460 KB |
Output is correct |
34 |
Correct |
66 ms |
127560 KB |
Output is correct |
35 |
Correct |
63 ms |
127456 KB |
Output is correct |
36 |
Correct |
262 ms |
127624 KB |
Output is correct |
37 |
Correct |
171 ms |
127480 KB |
Output is correct |
38 |
Correct |
99 ms |
127536 KB |
Output is correct |
39 |
Correct |
157 ms |
127536 KB |
Output is correct |
40 |
Correct |
192 ms |
127588 KB |
Output is correct |
41 |
Correct |
93 ms |
127460 KB |
Output is correct |
42 |
Correct |
81 ms |
127460 KB |
Output is correct |
43 |
Correct |
91 ms |
127460 KB |
Output is correct |
44 |
Correct |
66 ms |
127460 KB |
Output is correct |
45 |
Correct |
91 ms |
127588 KB |
Output is correct |
46 |
Correct |
77 ms |
127456 KB |
Output is correct |
47 |
Correct |
90 ms |
127460 KB |
Output is correct |
48 |
Correct |
81 ms |
127460 KB |
Output is correct |
49 |
Correct |
93 ms |
127588 KB |
Output is correct |
50 |
Correct |
72 ms |
127460 KB |
Output is correct |
51 |
Correct |
88 ms |
127588 KB |
Output is correct |
52 |
Correct |
66 ms |
127460 KB |
Output is correct |
53 |
Correct |
89 ms |
127460 KB |
Output is correct |
54 |
Correct |
70 ms |
127460 KB |
Output is correct |
55 |
Correct |
92 ms |
127460 KB |
Output is correct |
56 |
Correct |
73 ms |
127460 KB |
Output is correct |
57 |
Correct |
92 ms |
127460 KB |
Output is correct |
58 |
Correct |
75 ms |
127460 KB |
Output is correct |
59 |
Correct |
333 ms |
127460 KB |
Output is correct |
60 |
Correct |
209 ms |
127460 KB |
Output is correct |
61 |
Correct |
331 ms |
127588 KB |
Output is correct |
62 |
Correct |
211 ms |
127588 KB |
Output is correct |
63 |
Correct |
386 ms |
127464 KB |
Output is correct |
64 |
Correct |
209 ms |
127588 KB |
Output is correct |
65 |
Correct |
294 ms |
127460 KB |
Output is correct |
66 |
Correct |
267 ms |
127588 KB |
Output is correct |
67 |
Correct |
253 ms |
127544 KB |
Output is correct |
68 |
Correct |
229 ms |
127460 KB |
Output is correct |
69 |
Correct |
298 ms |
127540 KB |
Output is correct |
70 |
Correct |
320 ms |
127460 KB |
Output is correct |
71 |
Correct |
281 ms |
127456 KB |
Output is correct |
72 |
Correct |
297 ms |
127588 KB |
Output is correct |
73 |
Correct |
258 ms |
127460 KB |
Output is correct |
74 |
Correct |
244 ms |
127456 KB |
Output is correct |
75 |
Correct |
273 ms |
127592 KB |
Output is correct |
76 |
Correct |
328 ms |
127588 KB |
Output is correct |
77 |
Correct |
321 ms |
127588 KB |
Output is correct |
78 |
Correct |
239 ms |
127592 KB |
Output is correct |
79 |
Correct |
243 ms |
127460 KB |
Output is correct |
80 |
Correct |
312 ms |
127588 KB |
Output is correct |
81 |
Correct |
245 ms |
127460 KB |
Output is correct |
82 |
Correct |
279 ms |
127460 KB |
Output is correct |
83 |
Correct |
335 ms |
127460 KB |
Output is correct |
84 |
Correct |
276 ms |
127460 KB |
Output is correct |
85 |
Correct |
303 ms |
127588 KB |
Output is correct |
86 |
Correct |
307 ms |
127460 KB |
Output is correct |
87 |
Correct |
270 ms |
127588 KB |
Output is correct |
88 |
Correct |
354 ms |
127460 KB |
Output is correct |
89 |
Correct |
337 ms |
127656 KB |
Output is correct |
90 |
Correct |
272 ms |
127460 KB |
Output is correct |
91 |
Correct |
364 ms |
127592 KB |
Output is correct |
92 |
Correct |
343 ms |
127544 KB |
Output is correct |
93 |
Correct |
332 ms |
127540 KB |
Output is correct |