/***Farhan132***/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast,fast-math")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<ll> vll;
typedef pair<ll , ll> ii;
typedef vector< ii > vii;
typedef pair < pair < ll , ll > , pair < ll , ll > > cm;
typedef tuple < ll, ll, ll > tp;
#define ff first
#define ss second
#define pb push_back
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
//const ll mod = (ll) 998244353;
const ll mod = (ll) 1e9 + 7;
const ll maxn = (ll)1e8 + 5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = (ll)1e18;
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};
bool USACO = 0;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 205;
ll x[N] , t[N];
ll ans = 0, n , L;
ll dp[N][N][N][2];
ll g(ll x, ll y, ll z, ll a){
ll res = x;
res *= N;
res += y;
res *= N;
res += z;
res *= 2;
res += a;
return res;
}
ll dist(ll x, ll y){
return min(abs(x - y), L - abs(x-y));
}
void solve(){
cin >> n >> L;
x[0] = 0, t[0] = -1;
for(ll i = 1; i <= n; i++) cin >> x[i];
for(ll i = 1; i <= n; i++) cin >> t[i];
n++;
for(ll i = 0; i < N; i++){
for(ll j = 0; j < N; j++){
for(ll k = 0; k < N; k++){
for(ll x = 0; x < 2; x++) dp[i][j][k][x] = 1e18;
}
}
}
priority_queue < ii , vector < ii > , greater < ii > > p;
dp[0][0][0][0] = 0;
p.push({0, 0});
while(p.size()){
auto [time, w] = p.top(); p.pop();
ll border = w%2;
w /= 2;
ll tot = w%N;
w /= N;
ll r = w%N;
w /= N;
ll l = w;
ans = max(ans, tot);
if(border == 0){
ll L = (l - 1 + n)%n;
if(L != r){
ll dummy = tot;
if(time + dist(x[l], x[L]) <= t[L]) dummy++;
if(dp[L][r][dummy][0] > time + dist(x[l], x[L])){
dp[L][r][dummy][0] = time + dist(x[l] , x[L]);
p.push({time + dist(x[l], x[L]), g(L,r,dummy, 0)});
}
}
}else{
ll R = (r + 1)%n;
if(l != R){
ll dummy = tot;
if(time + dist(x[r], x[R]) <= t[R]) dummy++;
if(dp[l][R][dummy][1] > time + dist(x[r], x[R])){
dp[l][R][dummy][1] = time + dist(x[r], x[R]);
p.push({time + dist(x[r], x[R]), g(l,R,dummy,1)});
}
}
}
if(dp[l][r][tot][border^1] > dp[l][r][tot][border] + dist(x[l], x[r])){
dp[l][r][tot][border^1] = time + dist(x[l], x[r]);
p.push({time + dist(x[l], x[r]), g(l,r,tot,1-border)});
}
}
cout << ans << '\n';
return;
}
int main() {
#ifdef LOCAL
freopen("in", "r", stdin);
freopen("out", "w", stdout);
auto start_time = clock();
#else
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#endif
//pre();
ll T = 1, CT = 0; // cin >> T;
while(T--){
// cout << "Case #" << ++CT <<": " ;
solve();
}
#ifdef LOCAL
auto end_time = clock();
cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
#endif
return 0;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:163:15: warning: unused variable 'CT' [-Wunused-variable]
163 | ll T = 1, CT = 0; // cin >> T;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
135116 KB |
Output is correct |
2 |
Correct |
56 ms |
135148 KB |
Output is correct |
3 |
Correct |
57 ms |
135124 KB |
Output is correct |
4 |
Correct |
70 ms |
135112 KB |
Output is correct |
5 |
Correct |
64 ms |
135144 KB |
Output is correct |
6 |
Correct |
59 ms |
135192 KB |
Output is correct |
7 |
Correct |
52 ms |
135088 KB |
Output is correct |
8 |
Correct |
54 ms |
135168 KB |
Output is correct |
9 |
Correct |
55 ms |
135116 KB |
Output is correct |
10 |
Correct |
54 ms |
135112 KB |
Output is correct |
11 |
Correct |
56 ms |
135116 KB |
Output is correct |
12 |
Correct |
59 ms |
135092 KB |
Output is correct |
13 |
Correct |
60 ms |
135116 KB |
Output is correct |
14 |
Correct |
54 ms |
135096 KB |
Output is correct |
15 |
Correct |
53 ms |
135152 KB |
Output is correct |
16 |
Correct |
62 ms |
135116 KB |
Output is correct |
17 |
Correct |
55 ms |
135116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
135116 KB |
Output is correct |
2 |
Correct |
56 ms |
135148 KB |
Output is correct |
3 |
Correct |
57 ms |
135124 KB |
Output is correct |
4 |
Correct |
70 ms |
135112 KB |
Output is correct |
5 |
Correct |
64 ms |
135144 KB |
Output is correct |
6 |
Correct |
59 ms |
135192 KB |
Output is correct |
7 |
Correct |
52 ms |
135088 KB |
Output is correct |
8 |
Correct |
54 ms |
135168 KB |
Output is correct |
9 |
Correct |
55 ms |
135116 KB |
Output is correct |
10 |
Correct |
54 ms |
135112 KB |
Output is correct |
11 |
Correct |
56 ms |
135116 KB |
Output is correct |
12 |
Correct |
59 ms |
135092 KB |
Output is correct |
13 |
Correct |
60 ms |
135116 KB |
Output is correct |
14 |
Correct |
54 ms |
135096 KB |
Output is correct |
15 |
Correct |
53 ms |
135152 KB |
Output is correct |
16 |
Correct |
62 ms |
135116 KB |
Output is correct |
17 |
Correct |
55 ms |
135116 KB |
Output is correct |
18 |
Correct |
54 ms |
135152 KB |
Output is correct |
19 |
Correct |
55 ms |
135080 KB |
Output is correct |
20 |
Correct |
63 ms |
135104 KB |
Output is correct |
21 |
Correct |
64 ms |
135088 KB |
Output is correct |
22 |
Correct |
64 ms |
135076 KB |
Output is correct |
23 |
Correct |
58 ms |
135068 KB |
Output is correct |
24 |
Correct |
58 ms |
135144 KB |
Output is correct |
25 |
Correct |
65 ms |
135172 KB |
Output is correct |
26 |
Correct |
61 ms |
135092 KB |
Output is correct |
27 |
Correct |
65 ms |
135172 KB |
Output is correct |
28 |
Correct |
59 ms |
135128 KB |
Output is correct |
29 |
Correct |
61 ms |
135140 KB |
Output is correct |
30 |
Correct |
70 ms |
135112 KB |
Output is correct |
31 |
Correct |
65 ms |
135188 KB |
Output is correct |
32 |
Correct |
77 ms |
135076 KB |
Output is correct |
33 |
Correct |
70 ms |
135104 KB |
Output is correct |
34 |
Correct |
68 ms |
135084 KB |
Output is correct |
35 |
Correct |
65 ms |
135148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
135116 KB |
Output is correct |
2 |
Correct |
56 ms |
135148 KB |
Output is correct |
3 |
Correct |
57 ms |
135124 KB |
Output is correct |
4 |
Correct |
70 ms |
135112 KB |
Output is correct |
5 |
Correct |
64 ms |
135144 KB |
Output is correct |
6 |
Correct |
59 ms |
135192 KB |
Output is correct |
7 |
Correct |
52 ms |
135088 KB |
Output is correct |
8 |
Correct |
54 ms |
135168 KB |
Output is correct |
9 |
Correct |
55 ms |
135116 KB |
Output is correct |
10 |
Correct |
54 ms |
135112 KB |
Output is correct |
11 |
Correct |
56 ms |
135116 KB |
Output is correct |
12 |
Correct |
59 ms |
135092 KB |
Output is correct |
13 |
Correct |
60 ms |
135116 KB |
Output is correct |
14 |
Correct |
54 ms |
135096 KB |
Output is correct |
15 |
Correct |
53 ms |
135152 KB |
Output is correct |
16 |
Correct |
62 ms |
135116 KB |
Output is correct |
17 |
Correct |
55 ms |
135116 KB |
Output is correct |
18 |
Correct |
550 ms |
139336 KB |
Output is correct |
19 |
Correct |
298 ms |
137332 KB |
Output is correct |
20 |
Correct |
124 ms |
136344 KB |
Output is correct |
21 |
Correct |
232 ms |
137332 KB |
Output is correct |
22 |
Correct |
401 ms |
139472 KB |
Output is correct |
23 |
Correct |
86 ms |
135540 KB |
Output is correct |
24 |
Correct |
85 ms |
135788 KB |
Output is correct |
25 |
Correct |
97 ms |
135532 KB |
Output is correct |
26 |
Correct |
70 ms |
135368 KB |
Output is correct |
27 |
Correct |
88 ms |
135840 KB |
Output is correct |
28 |
Correct |
82 ms |
135800 KB |
Output is correct |
29 |
Correct |
120 ms |
135776 KB |
Output is correct |
30 |
Correct |
84 ms |
135752 KB |
Output is correct |
31 |
Correct |
134 ms |
135728 KB |
Output is correct |
32 |
Correct |
82 ms |
135840 KB |
Output is correct |
33 |
Correct |
122 ms |
135760 KB |
Output is correct |
34 |
Correct |
70 ms |
135356 KB |
Output is correct |
35 |
Correct |
84 ms |
135432 KB |
Output is correct |
36 |
Correct |
67 ms |
135500 KB |
Output is correct |
37 |
Correct |
80 ms |
135472 KB |
Output is correct |
38 |
Correct |
78 ms |
135768 KB |
Output is correct |
39 |
Correct |
82 ms |
135540 KB |
Output is correct |
40 |
Correct |
74 ms |
135468 KB |
Output is correct |
41 |
Correct |
858 ms |
143452 KB |
Output is correct |
42 |
Correct |
80 ms |
135324 KB |
Output is correct |
43 |
Correct |
809 ms |
143532 KB |
Output is correct |
44 |
Correct |
74 ms |
135352 KB |
Output is correct |
45 |
Correct |
818 ms |
143424 KB |
Output is correct |
46 |
Correct |
71 ms |
135300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
135116 KB |
Output is correct |
2 |
Correct |
56 ms |
135148 KB |
Output is correct |
3 |
Correct |
57 ms |
135124 KB |
Output is correct |
4 |
Correct |
70 ms |
135112 KB |
Output is correct |
5 |
Correct |
64 ms |
135144 KB |
Output is correct |
6 |
Correct |
59 ms |
135192 KB |
Output is correct |
7 |
Correct |
52 ms |
135088 KB |
Output is correct |
8 |
Correct |
54 ms |
135168 KB |
Output is correct |
9 |
Correct |
55 ms |
135116 KB |
Output is correct |
10 |
Correct |
54 ms |
135112 KB |
Output is correct |
11 |
Correct |
56 ms |
135116 KB |
Output is correct |
12 |
Correct |
59 ms |
135092 KB |
Output is correct |
13 |
Correct |
60 ms |
135116 KB |
Output is correct |
14 |
Correct |
54 ms |
135096 KB |
Output is correct |
15 |
Correct |
53 ms |
135152 KB |
Output is correct |
16 |
Correct |
62 ms |
135116 KB |
Output is correct |
17 |
Correct |
55 ms |
135116 KB |
Output is correct |
18 |
Correct |
54 ms |
135152 KB |
Output is correct |
19 |
Correct |
55 ms |
135080 KB |
Output is correct |
20 |
Correct |
63 ms |
135104 KB |
Output is correct |
21 |
Correct |
64 ms |
135088 KB |
Output is correct |
22 |
Correct |
64 ms |
135076 KB |
Output is correct |
23 |
Correct |
58 ms |
135068 KB |
Output is correct |
24 |
Correct |
58 ms |
135144 KB |
Output is correct |
25 |
Correct |
65 ms |
135172 KB |
Output is correct |
26 |
Correct |
61 ms |
135092 KB |
Output is correct |
27 |
Correct |
65 ms |
135172 KB |
Output is correct |
28 |
Correct |
59 ms |
135128 KB |
Output is correct |
29 |
Correct |
61 ms |
135140 KB |
Output is correct |
30 |
Correct |
70 ms |
135112 KB |
Output is correct |
31 |
Correct |
65 ms |
135188 KB |
Output is correct |
32 |
Correct |
77 ms |
135076 KB |
Output is correct |
33 |
Correct |
70 ms |
135104 KB |
Output is correct |
34 |
Correct |
68 ms |
135084 KB |
Output is correct |
35 |
Correct |
65 ms |
135148 KB |
Output is correct |
36 |
Correct |
550 ms |
139336 KB |
Output is correct |
37 |
Correct |
298 ms |
137332 KB |
Output is correct |
38 |
Correct |
124 ms |
136344 KB |
Output is correct |
39 |
Correct |
232 ms |
137332 KB |
Output is correct |
40 |
Correct |
401 ms |
139472 KB |
Output is correct |
41 |
Correct |
86 ms |
135540 KB |
Output is correct |
42 |
Correct |
85 ms |
135788 KB |
Output is correct |
43 |
Correct |
97 ms |
135532 KB |
Output is correct |
44 |
Correct |
70 ms |
135368 KB |
Output is correct |
45 |
Correct |
88 ms |
135840 KB |
Output is correct |
46 |
Correct |
82 ms |
135800 KB |
Output is correct |
47 |
Correct |
120 ms |
135776 KB |
Output is correct |
48 |
Correct |
84 ms |
135752 KB |
Output is correct |
49 |
Correct |
134 ms |
135728 KB |
Output is correct |
50 |
Correct |
82 ms |
135840 KB |
Output is correct |
51 |
Correct |
122 ms |
135760 KB |
Output is correct |
52 |
Correct |
70 ms |
135356 KB |
Output is correct |
53 |
Correct |
84 ms |
135432 KB |
Output is correct |
54 |
Correct |
67 ms |
135500 KB |
Output is correct |
55 |
Correct |
80 ms |
135472 KB |
Output is correct |
56 |
Correct |
78 ms |
135768 KB |
Output is correct |
57 |
Correct |
82 ms |
135540 KB |
Output is correct |
58 |
Correct |
74 ms |
135468 KB |
Output is correct |
59 |
Correct |
858 ms |
143452 KB |
Output is correct |
60 |
Correct |
80 ms |
135324 KB |
Output is correct |
61 |
Correct |
809 ms |
143532 KB |
Output is correct |
62 |
Correct |
74 ms |
135352 KB |
Output is correct |
63 |
Correct |
818 ms |
143424 KB |
Output is correct |
64 |
Correct |
71 ms |
135300 KB |
Output is correct |
65 |
Correct |
791 ms |
143508 KB |
Output is correct |
66 |
Correct |
606 ms |
139328 KB |
Output is correct |
67 |
Correct |
550 ms |
139372 KB |
Output is correct |
68 |
Correct |
529 ms |
139408 KB |
Output is correct |
69 |
Correct |
707 ms |
139512 KB |
Output is correct |
70 |
Correct |
170 ms |
136340 KB |
Output is correct |
71 |
Correct |
459 ms |
143484 KB |
Output is correct |
72 |
Correct |
139 ms |
136300 KB |
Output is correct |
73 |
Correct |
241 ms |
139452 KB |
Output is correct |
74 |
Correct |
141 ms |
136340 KB |
Output is correct |
75 |
Correct |
444 ms |
143444 KB |
Output is correct |
76 |
Correct |
700 ms |
137328 KB |
Output is correct |
77 |
Correct |
622 ms |
143460 KB |
Output is correct |
78 |
Correct |
418 ms |
137360 KB |
Output is correct |
79 |
Correct |
647 ms |
143432 KB |
Output is correct |
80 |
Correct |
611 ms |
137284 KB |
Output is correct |
81 |
Correct |
437 ms |
143536 KB |
Output is correct |
82 |
Correct |
343 ms |
137372 KB |
Output is correct |
83 |
Correct |
760 ms |
143488 KB |
Output is correct |
84 |
Correct |
329 ms |
137352 KB |
Output is correct |
85 |
Correct |
358 ms |
143524 KB |
Output is correct |
86 |
Correct |
384 ms |
137304 KB |
Output is correct |
87 |
Correct |
571 ms |
143512 KB |
Output is correct |
88 |
Correct |
794 ms |
139360 KB |
Output is correct |
89 |
Correct |
957 ms |
143472 KB |
Output is correct |
90 |
Correct |
90 ms |
135504 KB |
Output is correct |
91 |
Correct |
1117 ms |
143448 KB |
Output is correct |
92 |
Correct |
856 ms |
143484 KB |
Output is correct |
93 |
Correct |
74 ms |
135544 KB |
Output is correct |