#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<ll, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 2e2 + 5, lg = 22, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
ll dp[maxn][maxn][maxn<<1][2];
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n, l; cin >> n >> l;
vector<ll> x(n+1), t(n+1);
rep(i,1,n+1) cin >> x[i];
rep(i,1,n+1) cin >> t[i];
vector<ll> xn(n+1), tn(n+1);
rep(i,1,n+1) xn[i] = l - x[n+1-i], tn[i] = t[n+1-i];
int ans = 0;
rep(i,0,n+1) rep(j,0,n+1) rep(k,0,(n<<1)+1) rep(t,0,2) dp[i][j][k][t] = inf;
dp[0][0][0][0] = dp[0][0][0][1] = 0;
rep(i,0,n+1){
rep(j,0,n+1){
rep(k,0,(n<<1)+1){
// rep(t,0,2) if(dp[i][j][k][t] < inf) ans = max(ans, min(n, k)), er(i, j, k, t, dp[i][j][k][t]);
if(i < n){
ll tm = dp[i][j][k][0] + xn[i+1] - xn[i];
chkmin(dp[i+1][j][k + (tm <= tn[i+1])][0], tm);
tm = dp[i][j][k][1] + x[j] + xn[i+1];
chkmin(dp[i+1][j][k + (tm <= tn[i+1])][0], tm);
}
if(j < n){
ll tm = dp[i][j][k][0] + xn[i] + x[j+1];
chkmin(dp[i][j+1][k + (tm <= t[j+1])][1], tm);
tm = dp[i][j][k][1] + x[j+1] - x[j];
chkmin(dp[i][j+1][k + (tm <= t[j+1])][1], tm);
}
}
}
}
rep(i,0,n+1){
rep(k,0,n+1){
rep(t,0,2){
if(dp[i][n-i][k][t] < inf) ans = max(ans, k);
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
616 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
524 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
616 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
524 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1480 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
1 ms |
1492 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1492 KB |
Output is correct |
34 |
Correct |
1 ms |
1492 KB |
Output is correct |
35 |
Correct |
1 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
616 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
524 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
183 ms |
208880 KB |
Output is correct |
19 |
Correct |
101 ms |
126464 KB |
Output is correct |
20 |
Correct |
48 ms |
67228 KB |
Output is correct |
21 |
Correct |
90 ms |
119344 KB |
Output is correct |
22 |
Correct |
130 ms |
154996 KB |
Output is correct |
23 |
Correct |
41 ms |
57172 KB |
Output is correct |
24 |
Correct |
27 ms |
44584 KB |
Output is correct |
25 |
Correct |
40 ms |
56016 KB |
Output is correct |
26 |
Correct |
12 ms |
19108 KB |
Output is correct |
27 |
Correct |
43 ms |
58324 KB |
Output is correct |
28 |
Correct |
26 ms |
41532 KB |
Output is correct |
29 |
Correct |
41 ms |
59652 KB |
Output is correct |
30 |
Correct |
30 ms |
46796 KB |
Output is correct |
31 |
Correct |
44 ms |
56008 KB |
Output is correct |
32 |
Correct |
17 ms |
27728 KB |
Output is correct |
33 |
Correct |
39 ms |
56008 KB |
Output is correct |
34 |
Correct |
10 ms |
17620 KB |
Output is correct |
35 |
Correct |
33 ms |
54760 KB |
Output is correct |
36 |
Correct |
15 ms |
24052 KB |
Output is correct |
37 |
Correct |
36 ms |
58324 KB |
Output is correct |
38 |
Correct |
20 ms |
30796 KB |
Output is correct |
39 |
Correct |
37 ms |
60864 KB |
Output is correct |
40 |
Correct |
22 ms |
34868 KB |
Output is correct |
41 |
Correct |
249 ms |
257956 KB |
Output is correct |
42 |
Correct |
122 ms |
173384 KB |
Output is correct |
43 |
Correct |
239 ms |
257800 KB |
Output is correct |
44 |
Correct |
121 ms |
171340 KB |
Output is correct |
45 |
Correct |
243 ms |
257900 KB |
Output is correct |
46 |
Correct |
123 ms |
173528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
616 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
524 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1236 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1480 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1236 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1484 KB |
Output is correct |
30 |
Correct |
1 ms |
1492 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1492 KB |
Output is correct |
34 |
Correct |
1 ms |
1492 KB |
Output is correct |
35 |
Correct |
1 ms |
1484 KB |
Output is correct |
36 |
Correct |
183 ms |
208880 KB |
Output is correct |
37 |
Correct |
101 ms |
126464 KB |
Output is correct |
38 |
Correct |
48 ms |
67228 KB |
Output is correct |
39 |
Correct |
90 ms |
119344 KB |
Output is correct |
40 |
Correct |
130 ms |
154996 KB |
Output is correct |
41 |
Correct |
41 ms |
57172 KB |
Output is correct |
42 |
Correct |
27 ms |
44584 KB |
Output is correct |
43 |
Correct |
40 ms |
56016 KB |
Output is correct |
44 |
Correct |
12 ms |
19108 KB |
Output is correct |
45 |
Correct |
43 ms |
58324 KB |
Output is correct |
46 |
Correct |
26 ms |
41532 KB |
Output is correct |
47 |
Correct |
41 ms |
59652 KB |
Output is correct |
48 |
Correct |
30 ms |
46796 KB |
Output is correct |
49 |
Correct |
44 ms |
56008 KB |
Output is correct |
50 |
Correct |
17 ms |
27728 KB |
Output is correct |
51 |
Correct |
39 ms |
56008 KB |
Output is correct |
52 |
Correct |
10 ms |
17620 KB |
Output is correct |
53 |
Correct |
33 ms |
54760 KB |
Output is correct |
54 |
Correct |
15 ms |
24052 KB |
Output is correct |
55 |
Correct |
36 ms |
58324 KB |
Output is correct |
56 |
Correct |
20 ms |
30796 KB |
Output is correct |
57 |
Correct |
37 ms |
60864 KB |
Output is correct |
58 |
Correct |
22 ms |
34868 KB |
Output is correct |
59 |
Correct |
249 ms |
257956 KB |
Output is correct |
60 |
Correct |
122 ms |
173384 KB |
Output is correct |
61 |
Correct |
239 ms |
257800 KB |
Output is correct |
62 |
Correct |
121 ms |
171340 KB |
Output is correct |
63 |
Correct |
243 ms |
257900 KB |
Output is correct |
64 |
Correct |
123 ms |
173528 KB |
Output is correct |
65 |
Correct |
208 ms |
232788 KB |
Output is correct |
66 |
Correct |
209 ms |
213624 KB |
Output is correct |
67 |
Correct |
185 ms |
204300 KB |
Output is correct |
68 |
Correct |
168 ms |
188500 KB |
Output is correct |
69 |
Correct |
222 ms |
230476 KB |
Output is correct |
70 |
Correct |
222 ms |
220636 KB |
Output is correct |
71 |
Correct |
210 ms |
223056 KB |
Output is correct |
72 |
Correct |
226 ms |
225472 KB |
Output is correct |
73 |
Correct |
176 ms |
208916 KB |
Output is correct |
74 |
Correct |
189 ms |
195356 KB |
Output is correct |
75 |
Correct |
188 ms |
215948 KB |
Output is correct |
76 |
Correct |
238 ms |
247676 KB |
Output is correct |
77 |
Correct |
222 ms |
247660 KB |
Output is correct |
78 |
Correct |
176 ms |
190792 KB |
Output is correct |
79 |
Correct |
175 ms |
197472 KB |
Output is correct |
80 |
Correct |
243 ms |
242508 KB |
Output is correct |
81 |
Correct |
170 ms |
199628 KB |
Output is correct |
82 |
Correct |
174 ms |
211272 KB |
Output is correct |
83 |
Correct |
228 ms |
257848 KB |
Output is correct |
84 |
Correct |
185 ms |
220616 KB |
Output is correct |
85 |
Correct |
210 ms |
240148 KB |
Output is correct |
86 |
Correct |
195 ms |
235084 KB |
Output is correct |
87 |
Correct |
194 ms |
215920 KB |
Output is correct |
88 |
Correct |
262 ms |
260448 KB |
Output is correct |
89 |
Correct |
243 ms |
260360 KB |
Output is correct |
90 |
Correct |
159 ms |
218288 KB |
Output is correct |
91 |
Correct |
260 ms |
260432 KB |
Output is correct |
92 |
Correct |
242 ms |
260352 KB |
Output is correct |
93 |
Correct |
188 ms |
255180 KB |
Output is correct |