#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define REPD(i, a) for (int i = (a) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int nArr, L;
#define MAX 202
int A[MAX], T[MAX];
//min DP[l][r][picked][where] = time
//where = 0: clock wise
//where = 1: counter clock wise
int dp[MAX][MAX][MAX][2];
void process(void){
cin >> nArr >> L;
for (int i = 1; i <= nArr; ++i) cin >> A[i];
for (int i = 1; i <= nArr; ++i) cin >> T[i];
A[nArr + 1] = L;
memset(dp, 0x3f, sizeof dp);
REP(i, 2) dp[0][0][0][i] = 0;
REP(l, nArr) REP(r, nArr) REP(picked, nArr){
if(l + r + 1 > nArr) continue;
int cur = dp[l][r][picked][1];
bool can_pick = 0;
can_pick = (cur + (A[r + 1] - A[r]) <= T[r + 1]);
minimize(dp[l][r + 1][picked + can_pick][1], cur + (A[r + 1] - A[r]));
can_pick = (cur + (A[r] + L - A[nArr - l]) <= T[nArr - l]);
minimize(dp[l + 1][r][picked + can_pick][0], cur + (A[r] + L - A[nArr - l]));
cur = dp[l][r][picked][0];
can_pick = (cur + (A[nArr - l + 1] - A[nArr - l]) <= T[nArr - l]);
minimize(dp[l + 1][r][picked + can_pick][0], cur + (A[nArr - l + 1] - A[nArr - l]));
can_pick = (cur + (L - A[nArr - l + 1] + A[r + 1]) <= T[r + 1]);
minimize(dp[l][r + 1][picked + can_pick][1], cur + (L - A[nArr - l + 1] + A[r + 1]));
}
FORD(picked, 0, nArr) FOR(l, 0, nArr) FOR(r, 0, nArr) REP(where, 2){
if(dp[l][r][picked][where] < INF){
return void(cout << picked);
}
}
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
process();
return (0 ^ 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
129360 KB |
Output is correct |
2 |
Correct |
70 ms |
129364 KB |
Output is correct |
3 |
Correct |
68 ms |
129436 KB |
Output is correct |
4 |
Correct |
53 ms |
129360 KB |
Output is correct |
5 |
Correct |
59 ms |
129356 KB |
Output is correct |
6 |
Correct |
61 ms |
129364 KB |
Output is correct |
7 |
Correct |
50 ms |
129392 KB |
Output is correct |
8 |
Correct |
50 ms |
129364 KB |
Output is correct |
9 |
Correct |
54 ms |
129364 KB |
Output is correct |
10 |
Correct |
57 ms |
129228 KB |
Output is correct |
11 |
Correct |
57 ms |
129316 KB |
Output is correct |
12 |
Correct |
56 ms |
129476 KB |
Output is correct |
13 |
Correct |
72 ms |
129416 KB |
Output is correct |
14 |
Correct |
55 ms |
129360 KB |
Output is correct |
15 |
Correct |
65 ms |
129368 KB |
Output is correct |
16 |
Correct |
63 ms |
129260 KB |
Output is correct |
17 |
Correct |
52 ms |
129420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
129360 KB |
Output is correct |
2 |
Correct |
70 ms |
129364 KB |
Output is correct |
3 |
Correct |
68 ms |
129436 KB |
Output is correct |
4 |
Correct |
53 ms |
129360 KB |
Output is correct |
5 |
Correct |
59 ms |
129356 KB |
Output is correct |
6 |
Correct |
61 ms |
129364 KB |
Output is correct |
7 |
Correct |
50 ms |
129392 KB |
Output is correct |
8 |
Correct |
50 ms |
129364 KB |
Output is correct |
9 |
Correct |
54 ms |
129364 KB |
Output is correct |
10 |
Correct |
57 ms |
129228 KB |
Output is correct |
11 |
Correct |
57 ms |
129316 KB |
Output is correct |
12 |
Correct |
56 ms |
129476 KB |
Output is correct |
13 |
Correct |
72 ms |
129416 KB |
Output is correct |
14 |
Correct |
55 ms |
129360 KB |
Output is correct |
15 |
Correct |
65 ms |
129368 KB |
Output is correct |
16 |
Correct |
63 ms |
129260 KB |
Output is correct |
17 |
Correct |
52 ms |
129420 KB |
Output is correct |
18 |
Correct |
56 ms |
129360 KB |
Output is correct |
19 |
Correct |
62 ms |
129412 KB |
Output is correct |
20 |
Correct |
72 ms |
129364 KB |
Output is correct |
21 |
Correct |
64 ms |
129348 KB |
Output is correct |
22 |
Correct |
58 ms |
129360 KB |
Output is correct |
23 |
Correct |
57 ms |
129360 KB |
Output is correct |
24 |
Correct |
54 ms |
129360 KB |
Output is correct |
25 |
Correct |
61 ms |
129420 KB |
Output is correct |
26 |
Correct |
52 ms |
129384 KB |
Output is correct |
27 |
Correct |
68 ms |
129256 KB |
Output is correct |
28 |
Correct |
56 ms |
129360 KB |
Output is correct |
29 |
Correct |
56 ms |
129260 KB |
Output is correct |
30 |
Correct |
60 ms |
129320 KB |
Output is correct |
31 |
Correct |
68 ms |
129296 KB |
Output is correct |
32 |
Correct |
59 ms |
129328 KB |
Output is correct |
33 |
Correct |
51 ms |
129372 KB |
Output is correct |
34 |
Correct |
60 ms |
129368 KB |
Output is correct |
35 |
Correct |
51 ms |
129396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
129360 KB |
Output is correct |
2 |
Correct |
70 ms |
129364 KB |
Output is correct |
3 |
Correct |
68 ms |
129436 KB |
Output is correct |
4 |
Correct |
53 ms |
129360 KB |
Output is correct |
5 |
Correct |
59 ms |
129356 KB |
Output is correct |
6 |
Correct |
61 ms |
129364 KB |
Output is correct |
7 |
Correct |
50 ms |
129392 KB |
Output is correct |
8 |
Correct |
50 ms |
129364 KB |
Output is correct |
9 |
Correct |
54 ms |
129364 KB |
Output is correct |
10 |
Correct |
57 ms |
129228 KB |
Output is correct |
11 |
Correct |
57 ms |
129316 KB |
Output is correct |
12 |
Correct |
56 ms |
129476 KB |
Output is correct |
13 |
Correct |
72 ms |
129416 KB |
Output is correct |
14 |
Correct |
55 ms |
129360 KB |
Output is correct |
15 |
Correct |
65 ms |
129368 KB |
Output is correct |
16 |
Correct |
63 ms |
129260 KB |
Output is correct |
17 |
Correct |
52 ms |
129420 KB |
Output is correct |
18 |
Correct |
81 ms |
129360 KB |
Output is correct |
19 |
Correct |
68 ms |
129360 KB |
Output is correct |
20 |
Correct |
62 ms |
129364 KB |
Output is correct |
21 |
Correct |
72 ms |
129476 KB |
Output is correct |
22 |
Correct |
67 ms |
129360 KB |
Output is correct |
23 |
Correct |
56 ms |
129368 KB |
Output is correct |
24 |
Correct |
57 ms |
129420 KB |
Output is correct |
25 |
Correct |
60 ms |
129364 KB |
Output is correct |
26 |
Correct |
56 ms |
129364 KB |
Output is correct |
27 |
Correct |
55 ms |
129360 KB |
Output is correct |
28 |
Correct |
57 ms |
129364 KB |
Output is correct |
29 |
Correct |
56 ms |
129364 KB |
Output is correct |
30 |
Correct |
58 ms |
129296 KB |
Output is correct |
31 |
Correct |
56 ms |
129296 KB |
Output is correct |
32 |
Correct |
58 ms |
129360 KB |
Output is correct |
33 |
Correct |
56 ms |
129360 KB |
Output is correct |
34 |
Correct |
52 ms |
129364 KB |
Output is correct |
35 |
Correct |
62 ms |
129364 KB |
Output is correct |
36 |
Correct |
61 ms |
129436 KB |
Output is correct |
37 |
Correct |
62 ms |
129360 KB |
Output is correct |
38 |
Correct |
58 ms |
129372 KB |
Output is correct |
39 |
Correct |
65 ms |
129360 KB |
Output is correct |
40 |
Correct |
54 ms |
129360 KB |
Output is correct |
41 |
Correct |
80 ms |
129364 KB |
Output is correct |
42 |
Correct |
79 ms |
129288 KB |
Output is correct |
43 |
Correct |
79 ms |
129456 KB |
Output is correct |
44 |
Correct |
89 ms |
129248 KB |
Output is correct |
45 |
Correct |
85 ms |
129480 KB |
Output is correct |
46 |
Correct |
87 ms |
129452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
129360 KB |
Output is correct |
2 |
Correct |
70 ms |
129364 KB |
Output is correct |
3 |
Correct |
68 ms |
129436 KB |
Output is correct |
4 |
Correct |
53 ms |
129360 KB |
Output is correct |
5 |
Correct |
59 ms |
129356 KB |
Output is correct |
6 |
Correct |
61 ms |
129364 KB |
Output is correct |
7 |
Correct |
50 ms |
129392 KB |
Output is correct |
8 |
Correct |
50 ms |
129364 KB |
Output is correct |
9 |
Correct |
54 ms |
129364 KB |
Output is correct |
10 |
Correct |
57 ms |
129228 KB |
Output is correct |
11 |
Correct |
57 ms |
129316 KB |
Output is correct |
12 |
Correct |
56 ms |
129476 KB |
Output is correct |
13 |
Correct |
72 ms |
129416 KB |
Output is correct |
14 |
Correct |
55 ms |
129360 KB |
Output is correct |
15 |
Correct |
65 ms |
129368 KB |
Output is correct |
16 |
Correct |
63 ms |
129260 KB |
Output is correct |
17 |
Correct |
52 ms |
129420 KB |
Output is correct |
18 |
Correct |
56 ms |
129360 KB |
Output is correct |
19 |
Correct |
62 ms |
129412 KB |
Output is correct |
20 |
Correct |
72 ms |
129364 KB |
Output is correct |
21 |
Correct |
64 ms |
129348 KB |
Output is correct |
22 |
Correct |
58 ms |
129360 KB |
Output is correct |
23 |
Correct |
57 ms |
129360 KB |
Output is correct |
24 |
Correct |
54 ms |
129360 KB |
Output is correct |
25 |
Correct |
61 ms |
129420 KB |
Output is correct |
26 |
Correct |
52 ms |
129384 KB |
Output is correct |
27 |
Correct |
68 ms |
129256 KB |
Output is correct |
28 |
Correct |
56 ms |
129360 KB |
Output is correct |
29 |
Correct |
56 ms |
129260 KB |
Output is correct |
30 |
Correct |
60 ms |
129320 KB |
Output is correct |
31 |
Correct |
68 ms |
129296 KB |
Output is correct |
32 |
Correct |
59 ms |
129328 KB |
Output is correct |
33 |
Correct |
51 ms |
129372 KB |
Output is correct |
34 |
Correct |
60 ms |
129368 KB |
Output is correct |
35 |
Correct |
51 ms |
129396 KB |
Output is correct |
36 |
Correct |
81 ms |
129360 KB |
Output is correct |
37 |
Correct |
68 ms |
129360 KB |
Output is correct |
38 |
Correct |
62 ms |
129364 KB |
Output is correct |
39 |
Correct |
72 ms |
129476 KB |
Output is correct |
40 |
Correct |
67 ms |
129360 KB |
Output is correct |
41 |
Correct |
56 ms |
129368 KB |
Output is correct |
42 |
Correct |
57 ms |
129420 KB |
Output is correct |
43 |
Correct |
60 ms |
129364 KB |
Output is correct |
44 |
Correct |
56 ms |
129364 KB |
Output is correct |
45 |
Correct |
55 ms |
129360 KB |
Output is correct |
46 |
Correct |
57 ms |
129364 KB |
Output is correct |
47 |
Correct |
56 ms |
129364 KB |
Output is correct |
48 |
Correct |
58 ms |
129296 KB |
Output is correct |
49 |
Correct |
56 ms |
129296 KB |
Output is correct |
50 |
Correct |
58 ms |
129360 KB |
Output is correct |
51 |
Correct |
56 ms |
129360 KB |
Output is correct |
52 |
Correct |
52 ms |
129364 KB |
Output is correct |
53 |
Correct |
62 ms |
129364 KB |
Output is correct |
54 |
Correct |
61 ms |
129436 KB |
Output is correct |
55 |
Correct |
62 ms |
129360 KB |
Output is correct |
56 |
Correct |
58 ms |
129372 KB |
Output is correct |
57 |
Correct |
65 ms |
129360 KB |
Output is correct |
58 |
Correct |
54 ms |
129360 KB |
Output is correct |
59 |
Correct |
80 ms |
129364 KB |
Output is correct |
60 |
Correct |
79 ms |
129288 KB |
Output is correct |
61 |
Correct |
79 ms |
129456 KB |
Output is correct |
62 |
Correct |
89 ms |
129248 KB |
Output is correct |
63 |
Correct |
85 ms |
129480 KB |
Output is correct |
64 |
Correct |
87 ms |
129452 KB |
Output is correct |
65 |
Correct |
84 ms |
129300 KB |
Output is correct |
66 |
Correct |
85 ms |
129364 KB |
Output is correct |
67 |
Correct |
85 ms |
129276 KB |
Output is correct |
68 |
Correct |
77 ms |
129364 KB |
Output is correct |
69 |
Correct |
90 ms |
129480 KB |
Output is correct |
70 |
Correct |
75 ms |
129360 KB |
Output is correct |
71 |
Correct |
81 ms |
129364 KB |
Output is correct |
72 |
Correct |
71 ms |
129476 KB |
Output is correct |
73 |
Correct |
78 ms |
129364 KB |
Output is correct |
74 |
Correct |
73 ms |
129364 KB |
Output is correct |
75 |
Correct |
88 ms |
129260 KB |
Output is correct |
76 |
Correct |
78 ms |
129364 KB |
Output is correct |
77 |
Correct |
94 ms |
129364 KB |
Output is correct |
78 |
Correct |
75 ms |
129360 KB |
Output is correct |
79 |
Correct |
75 ms |
129480 KB |
Output is correct |
80 |
Correct |
78 ms |
129372 KB |
Output is correct |
81 |
Correct |
81 ms |
129320 KB |
Output is correct |
82 |
Correct |
96 ms |
129616 KB |
Output is correct |
83 |
Correct |
99 ms |
129364 KB |
Output is correct |
84 |
Correct |
83 ms |
129364 KB |
Output is correct |
85 |
Correct |
80 ms |
129364 KB |
Output is correct |
86 |
Correct |
86 ms |
129352 KB |
Output is correct |
87 |
Correct |
85 ms |
129380 KB |
Output is correct |
88 |
Correct |
80 ms |
129364 KB |
Output is correct |
89 |
Correct |
90 ms |
129364 KB |
Output is correct |
90 |
Correct |
91 ms |
129448 KB |
Output is correct |
91 |
Correct |
78 ms |
129360 KB |
Output is correct |
92 |
Correct |
98 ms |
129480 KB |
Output is correct |
93 |
Correct |
106 ms |
129328 KB |
Output is correct |