/* code by the cute ~~Dengdualang~~ PixelCat owo */
/* as cute as nacho neko (aka. my wife)! */
/* Nhade stay for a night here */
/* 183234 deng deng deng pixelcat oops */
/* (yang wang yesu)*2 */
/* ^ some weird stuff. nvm =w= */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int LL //__int128
#define double long double
using namespace std;
using LL = long long;
using LLL = __int128_t;
using uLL = unsigned long long;
using pii = pair<int, int>;
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define L(id) (id * 2 + 1)
#define R(id) (id * 2 + 2)
#define LO(x) (x & (-x))
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(998244353)
// #define MOD (int)((LL)1e9 + 7)
#define INF (int)(4e18)
// #define INF 1e9
#define EPS (1e-6)
#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
inline void NYA() {
ios::sync_with_stdio(false);
cin.tie(0);
}
inline int gcd(int a, int b) {
return __gcd(a, b);
}
inline int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int fpow(int b, int p, const int &mod) {
int ans = 1;
while (p) {
if (p & 1) ans = ans * b % mod;
p >>= 1;
b = b * b % mod;
}
return ans;
}
int fpow(int b, int p) {
return fpow(b, p, MOD);
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
if (_b > _a) _a = _b;
}
// mt19937_64 rng(
// chrono::steady_clock::now().time_since_epoch().count());
const int MAXN=210;
int x[MAXN];
int t[MAXN];
int dp[MAXN][MAXN][2][MAXN];
int32_t main() {
NYA();
// nyaacho >/////<
// miku sama bless me >/////<
int n,L; cin>>n>>L;
For(i,1,n) cin>>x[i];
For(i,1,n) cin>>t[i];
x[n+1]=L;
auto dist=[&](int a,int b) -> int{
int owo=(abs(x[a]-x[b]))%L;
return min(owo,L-owo);
};
memset(dp,0x3f3f3f3f,sizeof(dp));
dp[n+1][0][0][0]=dp[n+1][0][1][0]=0;
Forr(l,n+1,2) For(r,0,l-2) For(end,0,1) For(get,0,n){
auto &now=dp[l][r][end][get];
if(now>INF) continue;
int nx;
if(end) nx=r;
else nx=l;
// go to left
int tm=now+dist(nx,l-1);
chmin(dp[l-1][r][0][get+(tm<=t[l-1])],tm);
//go to right
tm=now+dist(nx,r+1);
chmin(dp[l][r+1][1][get+(tm<=t[r+1])],tm);
}
int ans=0;
Forr(l,n+1,1) For(r,0,l-1) For(end,0,1) For(get,0,n){
auto &now=dp[l][r][end][get];
if(now<INF){
chmax(ans,get);
}
}
cout<<ans<<"\n";
// debug(dp[7][0][0][0]);
// debug(dp[6][0][0][1]);
// debug(dp[5][0][0][2]);
// debug(dp[5][1][1][3]);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
145296 KB |
Output is correct |
2 |
Correct |
56 ms |
145188 KB |
Output is correct |
3 |
Correct |
53 ms |
145248 KB |
Output is correct |
4 |
Correct |
54 ms |
145224 KB |
Output is correct |
5 |
Correct |
55 ms |
145228 KB |
Output is correct |
6 |
Correct |
55 ms |
145288 KB |
Output is correct |
7 |
Correct |
55 ms |
145196 KB |
Output is correct |
8 |
Correct |
55 ms |
145280 KB |
Output is correct |
9 |
Correct |
54 ms |
145228 KB |
Output is correct |
10 |
Correct |
57 ms |
145220 KB |
Output is correct |
11 |
Correct |
55 ms |
145236 KB |
Output is correct |
12 |
Correct |
55 ms |
145172 KB |
Output is correct |
13 |
Correct |
69 ms |
145272 KB |
Output is correct |
14 |
Correct |
54 ms |
145212 KB |
Output is correct |
15 |
Correct |
56 ms |
145228 KB |
Output is correct |
16 |
Correct |
56 ms |
145172 KB |
Output is correct |
17 |
Correct |
57 ms |
145212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
145296 KB |
Output is correct |
2 |
Correct |
56 ms |
145188 KB |
Output is correct |
3 |
Correct |
53 ms |
145248 KB |
Output is correct |
4 |
Correct |
54 ms |
145224 KB |
Output is correct |
5 |
Correct |
55 ms |
145228 KB |
Output is correct |
6 |
Correct |
55 ms |
145288 KB |
Output is correct |
7 |
Correct |
55 ms |
145196 KB |
Output is correct |
8 |
Correct |
55 ms |
145280 KB |
Output is correct |
9 |
Correct |
54 ms |
145228 KB |
Output is correct |
10 |
Correct |
57 ms |
145220 KB |
Output is correct |
11 |
Correct |
55 ms |
145236 KB |
Output is correct |
12 |
Correct |
55 ms |
145172 KB |
Output is correct |
13 |
Correct |
69 ms |
145272 KB |
Output is correct |
14 |
Correct |
54 ms |
145212 KB |
Output is correct |
15 |
Correct |
56 ms |
145228 KB |
Output is correct |
16 |
Correct |
56 ms |
145172 KB |
Output is correct |
17 |
Correct |
57 ms |
145212 KB |
Output is correct |
18 |
Correct |
57 ms |
145260 KB |
Output is correct |
19 |
Correct |
56 ms |
145276 KB |
Output is correct |
20 |
Correct |
56 ms |
145228 KB |
Output is correct |
21 |
Correct |
55 ms |
145204 KB |
Output is correct |
22 |
Correct |
56 ms |
145212 KB |
Output is correct |
23 |
Correct |
65 ms |
145220 KB |
Output is correct |
24 |
Correct |
58 ms |
145192 KB |
Output is correct |
25 |
Correct |
63 ms |
145228 KB |
Output is correct |
26 |
Correct |
56 ms |
145172 KB |
Output is correct |
27 |
Correct |
57 ms |
145284 KB |
Output is correct |
28 |
Correct |
55 ms |
145180 KB |
Output is correct |
29 |
Correct |
60 ms |
145228 KB |
Output is correct |
30 |
Correct |
67 ms |
145264 KB |
Output is correct |
31 |
Correct |
54 ms |
145216 KB |
Output is correct |
32 |
Correct |
55 ms |
145236 KB |
Output is correct |
33 |
Correct |
54 ms |
145176 KB |
Output is correct |
34 |
Correct |
56 ms |
145260 KB |
Output is correct |
35 |
Correct |
68 ms |
145288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
145296 KB |
Output is correct |
2 |
Correct |
56 ms |
145188 KB |
Output is correct |
3 |
Correct |
53 ms |
145248 KB |
Output is correct |
4 |
Correct |
54 ms |
145224 KB |
Output is correct |
5 |
Correct |
55 ms |
145228 KB |
Output is correct |
6 |
Correct |
55 ms |
145288 KB |
Output is correct |
7 |
Correct |
55 ms |
145196 KB |
Output is correct |
8 |
Correct |
55 ms |
145280 KB |
Output is correct |
9 |
Correct |
54 ms |
145228 KB |
Output is correct |
10 |
Correct |
57 ms |
145220 KB |
Output is correct |
11 |
Correct |
55 ms |
145236 KB |
Output is correct |
12 |
Correct |
55 ms |
145172 KB |
Output is correct |
13 |
Correct |
69 ms |
145272 KB |
Output is correct |
14 |
Correct |
54 ms |
145212 KB |
Output is correct |
15 |
Correct |
56 ms |
145228 KB |
Output is correct |
16 |
Correct |
56 ms |
145172 KB |
Output is correct |
17 |
Correct |
57 ms |
145212 KB |
Output is correct |
18 |
Correct |
103 ms |
145228 KB |
Output is correct |
19 |
Correct |
83 ms |
145292 KB |
Output is correct |
20 |
Correct |
63 ms |
145268 KB |
Output is correct |
21 |
Correct |
75 ms |
145252 KB |
Output is correct |
22 |
Correct |
87 ms |
145272 KB |
Output is correct |
23 |
Correct |
72 ms |
145296 KB |
Output is correct |
24 |
Correct |
67 ms |
145292 KB |
Output is correct |
25 |
Correct |
65 ms |
145292 KB |
Output is correct |
26 |
Correct |
61 ms |
145244 KB |
Output is correct |
27 |
Correct |
69 ms |
145260 KB |
Output is correct |
28 |
Correct |
74 ms |
145228 KB |
Output is correct |
29 |
Correct |
77 ms |
145196 KB |
Output is correct |
30 |
Correct |
60 ms |
145288 KB |
Output is correct |
31 |
Correct |
69 ms |
145228 KB |
Output is correct |
32 |
Correct |
70 ms |
145268 KB |
Output is correct |
33 |
Correct |
65 ms |
145280 KB |
Output is correct |
34 |
Correct |
54 ms |
145260 KB |
Output is correct |
35 |
Correct |
60 ms |
145356 KB |
Output is correct |
36 |
Correct |
56 ms |
145292 KB |
Output is correct |
37 |
Correct |
60 ms |
145252 KB |
Output is correct |
38 |
Correct |
63 ms |
145276 KB |
Output is correct |
39 |
Correct |
60 ms |
145212 KB |
Output is correct |
40 |
Correct |
58 ms |
145260 KB |
Output is correct |
41 |
Correct |
122 ms |
145392 KB |
Output is correct |
42 |
Correct |
64 ms |
145292 KB |
Output is correct |
43 |
Correct |
127 ms |
145204 KB |
Output is correct |
44 |
Correct |
73 ms |
145252 KB |
Output is correct |
45 |
Correct |
136 ms |
145284 KB |
Output is correct |
46 |
Correct |
79 ms |
145328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
145296 KB |
Output is correct |
2 |
Correct |
56 ms |
145188 KB |
Output is correct |
3 |
Correct |
53 ms |
145248 KB |
Output is correct |
4 |
Correct |
54 ms |
145224 KB |
Output is correct |
5 |
Correct |
55 ms |
145228 KB |
Output is correct |
6 |
Correct |
55 ms |
145288 KB |
Output is correct |
7 |
Correct |
55 ms |
145196 KB |
Output is correct |
8 |
Correct |
55 ms |
145280 KB |
Output is correct |
9 |
Correct |
54 ms |
145228 KB |
Output is correct |
10 |
Correct |
57 ms |
145220 KB |
Output is correct |
11 |
Correct |
55 ms |
145236 KB |
Output is correct |
12 |
Correct |
55 ms |
145172 KB |
Output is correct |
13 |
Correct |
69 ms |
145272 KB |
Output is correct |
14 |
Correct |
54 ms |
145212 KB |
Output is correct |
15 |
Correct |
56 ms |
145228 KB |
Output is correct |
16 |
Correct |
56 ms |
145172 KB |
Output is correct |
17 |
Correct |
57 ms |
145212 KB |
Output is correct |
18 |
Correct |
57 ms |
145260 KB |
Output is correct |
19 |
Correct |
56 ms |
145276 KB |
Output is correct |
20 |
Correct |
56 ms |
145228 KB |
Output is correct |
21 |
Correct |
55 ms |
145204 KB |
Output is correct |
22 |
Correct |
56 ms |
145212 KB |
Output is correct |
23 |
Correct |
65 ms |
145220 KB |
Output is correct |
24 |
Correct |
58 ms |
145192 KB |
Output is correct |
25 |
Correct |
63 ms |
145228 KB |
Output is correct |
26 |
Correct |
56 ms |
145172 KB |
Output is correct |
27 |
Correct |
57 ms |
145284 KB |
Output is correct |
28 |
Correct |
55 ms |
145180 KB |
Output is correct |
29 |
Correct |
60 ms |
145228 KB |
Output is correct |
30 |
Correct |
67 ms |
145264 KB |
Output is correct |
31 |
Correct |
54 ms |
145216 KB |
Output is correct |
32 |
Correct |
55 ms |
145236 KB |
Output is correct |
33 |
Correct |
54 ms |
145176 KB |
Output is correct |
34 |
Correct |
56 ms |
145260 KB |
Output is correct |
35 |
Correct |
68 ms |
145288 KB |
Output is correct |
36 |
Correct |
103 ms |
145228 KB |
Output is correct |
37 |
Correct |
83 ms |
145292 KB |
Output is correct |
38 |
Correct |
63 ms |
145268 KB |
Output is correct |
39 |
Correct |
75 ms |
145252 KB |
Output is correct |
40 |
Correct |
87 ms |
145272 KB |
Output is correct |
41 |
Correct |
72 ms |
145296 KB |
Output is correct |
42 |
Correct |
67 ms |
145292 KB |
Output is correct |
43 |
Correct |
65 ms |
145292 KB |
Output is correct |
44 |
Correct |
61 ms |
145244 KB |
Output is correct |
45 |
Correct |
69 ms |
145260 KB |
Output is correct |
46 |
Correct |
74 ms |
145228 KB |
Output is correct |
47 |
Correct |
77 ms |
145196 KB |
Output is correct |
48 |
Correct |
60 ms |
145288 KB |
Output is correct |
49 |
Correct |
69 ms |
145228 KB |
Output is correct |
50 |
Correct |
70 ms |
145268 KB |
Output is correct |
51 |
Correct |
65 ms |
145280 KB |
Output is correct |
52 |
Correct |
54 ms |
145260 KB |
Output is correct |
53 |
Correct |
60 ms |
145356 KB |
Output is correct |
54 |
Correct |
56 ms |
145292 KB |
Output is correct |
55 |
Correct |
60 ms |
145252 KB |
Output is correct |
56 |
Correct |
63 ms |
145276 KB |
Output is correct |
57 |
Correct |
60 ms |
145212 KB |
Output is correct |
58 |
Correct |
58 ms |
145260 KB |
Output is correct |
59 |
Correct |
122 ms |
145392 KB |
Output is correct |
60 |
Correct |
64 ms |
145292 KB |
Output is correct |
61 |
Correct |
127 ms |
145204 KB |
Output is correct |
62 |
Correct |
73 ms |
145252 KB |
Output is correct |
63 |
Correct |
136 ms |
145284 KB |
Output is correct |
64 |
Correct |
79 ms |
145328 KB |
Output is correct |
65 |
Correct |
121 ms |
145292 KB |
Output is correct |
66 |
Correct |
108 ms |
145296 KB |
Output is correct |
67 |
Correct |
105 ms |
145260 KB |
Output is correct |
68 |
Correct |
95 ms |
145264 KB |
Output is correct |
69 |
Correct |
114 ms |
145204 KB |
Output is correct |
70 |
Correct |
113 ms |
145292 KB |
Output is correct |
71 |
Correct |
101 ms |
145292 KB |
Output is correct |
72 |
Correct |
129 ms |
145228 KB |
Output is correct |
73 |
Correct |
92 ms |
145300 KB |
Output is correct |
74 |
Correct |
105 ms |
145292 KB |
Output is correct |
75 |
Correct |
92 ms |
145292 KB |
Output is correct |
76 |
Correct |
134 ms |
145292 KB |
Output is correct |
77 |
Correct |
117 ms |
145272 KB |
Output is correct |
78 |
Correct |
111 ms |
145340 KB |
Output is correct |
79 |
Correct |
100 ms |
145216 KB |
Output is correct |
80 |
Correct |
132 ms |
145292 KB |
Output is correct |
81 |
Correct |
92 ms |
145288 KB |
Output is correct |
82 |
Correct |
85 ms |
145288 KB |
Output is correct |
83 |
Correct |
114 ms |
145296 KB |
Output is correct |
84 |
Correct |
85 ms |
145228 KB |
Output is correct |
85 |
Correct |
98 ms |
145264 KB |
Output is correct |
86 |
Correct |
105 ms |
145268 KB |
Output is correct |
87 |
Correct |
115 ms |
145228 KB |
Output is correct |
88 |
Correct |
149 ms |
145228 KB |
Output is correct |
89 |
Correct |
125 ms |
145184 KB |
Output is correct |
90 |
Correct |
68 ms |
145292 KB |
Output is correct |
91 |
Correct |
158 ms |
145292 KB |
Output is correct |
92 |
Correct |
131 ms |
145324 KB |
Output is correct |
93 |
Correct |
69 ms |
145292 KB |
Output is correct |