#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 205;
const ll INF = 1e18 + 69;
int n, l;
ll dp[N][N][N][2];
int x[N], t[N];
ll dis_on_circle(ll a, ll b){
return min((b - a + l) % l, (a - b + l) % l);
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
cin >> n >> l;
for(int i= 0; i<n; ++i)
cin >> x[i];
for(int j= 0; j<n; ++j)
cin >> t[j];
for(int i = 0; i<=n; ++i) for(int j = 0; j<=n; ++j) for(int k = 0; k<=n; ++k) dp[i][j][k][0] = dp[i][j][k][1] = INF;
dp[1][0][x[0] <= t[0]][0] = x[0];
dp[0][1][(l - x[n-1]) <= t[n-1]][1] = l - x[n-1];
int ans = 0;
for(int i = 0; i<=n; ++i) for(int j = 0; j <= n - i; ++j) for(int k = 0; k <= i + j; ++k){
for(int z = 0; z <= 1; ++z) if (dp[i][j][k][z] != INF){
ll val = dp[i][j][k][z];
// cout << i << " " << j << " " << k << " " << z << " " << val << "\n";
maximize(ans, k);
if (z == 0) {
if (i + j < n){
ll nxt_val1 = val + dis_on_circle(x[i], x[i-1]);
minimize(dp[i+1][j][k + (nxt_val1 <= t[i])][0], nxt_val1);
ll nxt_val2 = val + dis_on_circle(x[i-1], x[n- j - 1]);
minimize(dp[i][j+1][k + (nxt_val2 <= t[n-j-1])][1], nxt_val2);
}
}
else {
if (i + j < n){
ll nxt_val1 = val + dis_on_circle(x[n-j], x[i]);
minimize(dp[i+1][j][k + (nxt_val1 <= t[i])][0], nxt_val1);
ll nxt_val2 = val + dis_on_circle(x[n-j], x[n- j - 1]);
minimize(dp[i][j+1][k + (nxt_val2 <= t[n-j-1])][1], nxt_val2);
}
}
}
}
cout << ans << "\n";
cerr << "Time elapsed: " << clock() - start << " ms\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
10584 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6612 KB |
Output is correct |
23 |
Correct |
1 ms |
10588 KB |
Output is correct |
24 |
Correct |
1 ms |
10588 KB |
Output is correct |
25 |
Correct |
1 ms |
10584 KB |
Output is correct |
26 |
Correct |
1 ms |
10768 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
1 ms |
10584 KB |
Output is correct |
31 |
Correct |
1 ms |
10588 KB |
Output is correct |
32 |
Correct |
1 ms |
10588 KB |
Output is correct |
33 |
Correct |
1 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
1 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
40 ms |
119644 KB |
Output is correct |
19 |
Correct |
24 ms |
92968 KB |
Output is correct |
20 |
Correct |
12 ms |
68188 KB |
Output is correct |
21 |
Correct |
22 ms |
90968 KB |
Output is correct |
22 |
Correct |
29 ms |
103004 KB |
Output is correct |
23 |
Correct |
11 ms |
62044 KB |
Output is correct |
24 |
Correct |
7 ms |
55896 KB |
Output is correct |
25 |
Correct |
10 ms |
62208 KB |
Output is correct |
26 |
Correct |
4 ms |
37468 KB |
Output is correct |
27 |
Correct |
11 ms |
64092 KB |
Output is correct |
28 |
Correct |
6 ms |
53928 KB |
Output is correct |
29 |
Correct |
10 ms |
64212 KB |
Output is correct |
30 |
Correct |
8 ms |
55900 KB |
Output is correct |
31 |
Correct |
11 ms |
62044 KB |
Output is correct |
32 |
Correct |
6 ms |
45656 KB |
Output is correct |
33 |
Correct |
10 ms |
62168 KB |
Output is correct |
34 |
Correct |
4 ms |
37468 KB |
Output is correct |
35 |
Correct |
8 ms |
62092 KB |
Output is correct |
36 |
Correct |
5 ms |
41564 KB |
Output is correct |
37 |
Correct |
8 ms |
64092 KB |
Output is correct |
38 |
Correct |
6 ms |
47708 KB |
Output is correct |
39 |
Correct |
10 ms |
64200 KB |
Output is correct |
40 |
Correct |
6 ms |
49756 KB |
Output is correct |
41 |
Correct |
54 ms |
133996 KB |
Output is correct |
42 |
Correct |
17 ms |
109400 KB |
Output is correct |
43 |
Correct |
53 ms |
134000 KB |
Output is correct |
44 |
Correct |
17 ms |
109404 KB |
Output is correct |
45 |
Correct |
50 ms |
133980 KB |
Output is correct |
46 |
Correct |
16 ms |
109148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
10584 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6612 KB |
Output is correct |
23 |
Correct |
1 ms |
10588 KB |
Output is correct |
24 |
Correct |
1 ms |
10588 KB |
Output is correct |
25 |
Correct |
1 ms |
10584 KB |
Output is correct |
26 |
Correct |
1 ms |
10768 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
1 ms |
10584 KB |
Output is correct |
31 |
Correct |
1 ms |
10588 KB |
Output is correct |
32 |
Correct |
1 ms |
10588 KB |
Output is correct |
33 |
Correct |
1 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
1 ms |
10588 KB |
Output is correct |
36 |
Correct |
40 ms |
119644 KB |
Output is correct |
37 |
Correct |
24 ms |
92968 KB |
Output is correct |
38 |
Correct |
12 ms |
68188 KB |
Output is correct |
39 |
Correct |
22 ms |
90968 KB |
Output is correct |
40 |
Correct |
29 ms |
103004 KB |
Output is correct |
41 |
Correct |
11 ms |
62044 KB |
Output is correct |
42 |
Correct |
7 ms |
55896 KB |
Output is correct |
43 |
Correct |
10 ms |
62208 KB |
Output is correct |
44 |
Correct |
4 ms |
37468 KB |
Output is correct |
45 |
Correct |
11 ms |
64092 KB |
Output is correct |
46 |
Correct |
6 ms |
53928 KB |
Output is correct |
47 |
Correct |
10 ms |
64212 KB |
Output is correct |
48 |
Correct |
8 ms |
55900 KB |
Output is correct |
49 |
Correct |
11 ms |
62044 KB |
Output is correct |
50 |
Correct |
6 ms |
45656 KB |
Output is correct |
51 |
Correct |
10 ms |
62168 KB |
Output is correct |
52 |
Correct |
4 ms |
37468 KB |
Output is correct |
53 |
Correct |
8 ms |
62092 KB |
Output is correct |
54 |
Correct |
5 ms |
41564 KB |
Output is correct |
55 |
Correct |
8 ms |
64092 KB |
Output is correct |
56 |
Correct |
6 ms |
47708 KB |
Output is correct |
57 |
Correct |
10 ms |
64200 KB |
Output is correct |
58 |
Correct |
6 ms |
49756 KB |
Output is correct |
59 |
Correct |
54 ms |
133996 KB |
Output is correct |
60 |
Correct |
17 ms |
109400 KB |
Output is correct |
61 |
Correct |
53 ms |
134000 KB |
Output is correct |
62 |
Correct |
17 ms |
109404 KB |
Output is correct |
63 |
Correct |
50 ms |
133980 KB |
Output is correct |
64 |
Correct |
16 ms |
109148 KB |
Output is correct |
65 |
Correct |
51 ms |
125672 KB |
Output is correct |
66 |
Correct |
43 ms |
121692 KB |
Output is correct |
67 |
Correct |
38 ms |
117592 KB |
Output is correct |
68 |
Correct |
36 ms |
113500 KB |
Output is correct |
69 |
Correct |
46 ms |
125788 KB |
Output is correct |
70 |
Correct |
42 ms |
123736 KB |
Output is correct |
71 |
Correct |
37 ms |
123736 KB |
Output is correct |
72 |
Correct |
50 ms |
123740 KB |
Output is correct |
73 |
Correct |
28 ms |
119644 KB |
Output is correct |
74 |
Correct |
37 ms |
115412 KB |
Output is correct |
75 |
Correct |
37 ms |
121688 KB |
Output is correct |
76 |
Correct |
58 ms |
129908 KB |
Output is correct |
77 |
Correct |
43 ms |
129884 KB |
Output is correct |
78 |
Correct |
41 ms |
115536 KB |
Output is correct |
79 |
Correct |
38 ms |
115544 KB |
Output is correct |
80 |
Correct |
56 ms |
129884 KB |
Output is correct |
81 |
Correct |
35 ms |
117592 KB |
Output is correct |
82 |
Correct |
30 ms |
119640 KB |
Output is correct |
83 |
Correct |
44 ms |
133976 KB |
Output is correct |
84 |
Correct |
32 ms |
123660 KB |
Output is correct |
85 |
Correct |
36 ms |
127836 KB |
Output is correct |
86 |
Correct |
34 ms |
127836 KB |
Output is correct |
87 |
Correct |
42 ms |
121692 KB |
Output is correct |
88 |
Correct |
65 ms |
134000 KB |
Output is correct |
89 |
Correct |
52 ms |
133980 KB |
Output is correct |
90 |
Correct |
19 ms |
121692 KB |
Output is correct |
91 |
Correct |
65 ms |
133844 KB |
Output is correct |
92 |
Correct |
55 ms |
133980 KB |
Output is correct |
93 |
Correct |
22 ms |
131928 KB |
Output is correct |