#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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
129364 KB |
Output is correct |
2 |
Correct |
56 ms |
129364 KB |
Output is correct |
3 |
Correct |
58 ms |
129724 KB |
Output is correct |
4 |
Correct |
51 ms |
129364 KB |
Output is correct |
5 |
Correct |
50 ms |
129364 KB |
Output is correct |
6 |
Correct |
50 ms |
129368 KB |
Output is correct |
7 |
Correct |
51 ms |
129364 KB |
Output is correct |
8 |
Correct |
51 ms |
129356 KB |
Output is correct |
9 |
Correct |
51 ms |
129360 KB |
Output is correct |
10 |
Correct |
50 ms |
129376 KB |
Output is correct |
11 |
Correct |
56 ms |
129360 KB |
Output is correct |
12 |
Correct |
52 ms |
129360 KB |
Output is correct |
13 |
Correct |
50 ms |
129364 KB |
Output is correct |
14 |
Correct |
64 ms |
129360 KB |
Output is correct |
15 |
Correct |
54 ms |
129428 KB |
Output is correct |
16 |
Correct |
50 ms |
129364 KB |
Output is correct |
17 |
Correct |
56 ms |
129364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
129364 KB |
Output is correct |
2 |
Correct |
56 ms |
129364 KB |
Output is correct |
3 |
Correct |
58 ms |
129724 KB |
Output is correct |
4 |
Correct |
51 ms |
129364 KB |
Output is correct |
5 |
Correct |
50 ms |
129364 KB |
Output is correct |
6 |
Correct |
50 ms |
129368 KB |
Output is correct |
7 |
Correct |
51 ms |
129364 KB |
Output is correct |
8 |
Correct |
51 ms |
129356 KB |
Output is correct |
9 |
Correct |
51 ms |
129360 KB |
Output is correct |
10 |
Correct |
50 ms |
129376 KB |
Output is correct |
11 |
Correct |
56 ms |
129360 KB |
Output is correct |
12 |
Correct |
52 ms |
129360 KB |
Output is correct |
13 |
Correct |
50 ms |
129364 KB |
Output is correct |
14 |
Correct |
64 ms |
129360 KB |
Output is correct |
15 |
Correct |
54 ms |
129428 KB |
Output is correct |
16 |
Correct |
50 ms |
129364 KB |
Output is correct |
17 |
Correct |
56 ms |
129364 KB |
Output is correct |
18 |
Correct |
50 ms |
129364 KB |
Output is correct |
19 |
Correct |
49 ms |
129364 KB |
Output is correct |
20 |
Correct |
51 ms |
129364 KB |
Output is correct |
21 |
Correct |
50 ms |
129356 KB |
Output is correct |
22 |
Correct |
49 ms |
129364 KB |
Output is correct |
23 |
Correct |
54 ms |
129360 KB |
Output is correct |
24 |
Correct |
56 ms |
129404 KB |
Output is correct |
25 |
Correct |
60 ms |
129364 KB |
Output is correct |
26 |
Correct |
56 ms |
129272 KB |
Output is correct |
27 |
Correct |
58 ms |
129352 KB |
Output is correct |
28 |
Correct |
56 ms |
129364 KB |
Output is correct |
29 |
Correct |
50 ms |
129232 KB |
Output is correct |
30 |
Correct |
50 ms |
129332 KB |
Output is correct |
31 |
Correct |
58 ms |
129252 KB |
Output is correct |
32 |
Correct |
57 ms |
129364 KB |
Output is correct |
33 |
Correct |
50 ms |
129368 KB |
Output is correct |
34 |
Correct |
50 ms |
129360 KB |
Output is correct |
35 |
Correct |
50 ms |
129352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
129364 KB |
Output is correct |
2 |
Correct |
56 ms |
129364 KB |
Output is correct |
3 |
Correct |
58 ms |
129724 KB |
Output is correct |
4 |
Correct |
51 ms |
129364 KB |
Output is correct |
5 |
Correct |
50 ms |
129364 KB |
Output is correct |
6 |
Correct |
50 ms |
129368 KB |
Output is correct |
7 |
Correct |
51 ms |
129364 KB |
Output is correct |
8 |
Correct |
51 ms |
129356 KB |
Output is correct |
9 |
Correct |
51 ms |
129360 KB |
Output is correct |
10 |
Correct |
50 ms |
129376 KB |
Output is correct |
11 |
Correct |
56 ms |
129360 KB |
Output is correct |
12 |
Correct |
52 ms |
129360 KB |
Output is correct |
13 |
Correct |
50 ms |
129364 KB |
Output is correct |
14 |
Correct |
64 ms |
129360 KB |
Output is correct |
15 |
Correct |
54 ms |
129428 KB |
Output is correct |
16 |
Correct |
50 ms |
129364 KB |
Output is correct |
17 |
Correct |
56 ms |
129364 KB |
Output is correct |
18 |
Correct |
76 ms |
129360 KB |
Output is correct |
19 |
Correct |
62 ms |
129360 KB |
Output is correct |
20 |
Correct |
56 ms |
129364 KB |
Output is correct |
21 |
Correct |
63 ms |
129360 KB |
Output is correct |
22 |
Correct |
66 ms |
129228 KB |
Output is correct |
23 |
Correct |
53 ms |
129416 KB |
Output is correct |
24 |
Correct |
53 ms |
129360 KB |
Output is correct |
25 |
Correct |
57 ms |
129408 KB |
Output is correct |
26 |
Correct |
51 ms |
129280 KB |
Output is correct |
27 |
Correct |
79 ms |
129364 KB |
Output is correct |
28 |
Correct |
55 ms |
129372 KB |
Output is correct |
29 |
Correct |
54 ms |
129264 KB |
Output is correct |
30 |
Correct |
56 ms |
129360 KB |
Output is correct |
31 |
Correct |
78 ms |
129364 KB |
Output is correct |
32 |
Correct |
52 ms |
129400 KB |
Output is correct |
33 |
Correct |
53 ms |
129364 KB |
Output is correct |
34 |
Correct |
52 ms |
129360 KB |
Output is correct |
35 |
Correct |
61 ms |
129316 KB |
Output is correct |
36 |
Correct |
54 ms |
129476 KB |
Output is correct |
37 |
Correct |
64 ms |
129416 KB |
Output is correct |
38 |
Correct |
55 ms |
129248 KB |
Output is correct |
39 |
Correct |
88 ms |
129368 KB |
Output is correct |
40 |
Correct |
59 ms |
129380 KB |
Output is correct |
41 |
Correct |
86 ms |
129484 KB |
Output is correct |
42 |
Correct |
89 ms |
129372 KB |
Output is correct |
43 |
Correct |
93 ms |
129396 KB |
Output is correct |
44 |
Correct |
80 ms |
129408 KB |
Output is correct |
45 |
Correct |
82 ms |
129476 KB |
Output is correct |
46 |
Correct |
80 ms |
129484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
129364 KB |
Output is correct |
2 |
Correct |
56 ms |
129364 KB |
Output is correct |
3 |
Correct |
58 ms |
129724 KB |
Output is correct |
4 |
Correct |
51 ms |
129364 KB |
Output is correct |
5 |
Correct |
50 ms |
129364 KB |
Output is correct |
6 |
Correct |
50 ms |
129368 KB |
Output is correct |
7 |
Correct |
51 ms |
129364 KB |
Output is correct |
8 |
Correct |
51 ms |
129356 KB |
Output is correct |
9 |
Correct |
51 ms |
129360 KB |
Output is correct |
10 |
Correct |
50 ms |
129376 KB |
Output is correct |
11 |
Correct |
56 ms |
129360 KB |
Output is correct |
12 |
Correct |
52 ms |
129360 KB |
Output is correct |
13 |
Correct |
50 ms |
129364 KB |
Output is correct |
14 |
Correct |
64 ms |
129360 KB |
Output is correct |
15 |
Correct |
54 ms |
129428 KB |
Output is correct |
16 |
Correct |
50 ms |
129364 KB |
Output is correct |
17 |
Correct |
56 ms |
129364 KB |
Output is correct |
18 |
Correct |
50 ms |
129364 KB |
Output is correct |
19 |
Correct |
49 ms |
129364 KB |
Output is correct |
20 |
Correct |
51 ms |
129364 KB |
Output is correct |
21 |
Correct |
50 ms |
129356 KB |
Output is correct |
22 |
Correct |
49 ms |
129364 KB |
Output is correct |
23 |
Correct |
54 ms |
129360 KB |
Output is correct |
24 |
Correct |
56 ms |
129404 KB |
Output is correct |
25 |
Correct |
60 ms |
129364 KB |
Output is correct |
26 |
Correct |
56 ms |
129272 KB |
Output is correct |
27 |
Correct |
58 ms |
129352 KB |
Output is correct |
28 |
Correct |
56 ms |
129364 KB |
Output is correct |
29 |
Correct |
50 ms |
129232 KB |
Output is correct |
30 |
Correct |
50 ms |
129332 KB |
Output is correct |
31 |
Correct |
58 ms |
129252 KB |
Output is correct |
32 |
Correct |
57 ms |
129364 KB |
Output is correct |
33 |
Correct |
50 ms |
129368 KB |
Output is correct |
34 |
Correct |
50 ms |
129360 KB |
Output is correct |
35 |
Correct |
50 ms |
129352 KB |
Output is correct |
36 |
Correct |
76 ms |
129360 KB |
Output is correct |
37 |
Correct |
62 ms |
129360 KB |
Output is correct |
38 |
Correct |
56 ms |
129364 KB |
Output is correct |
39 |
Correct |
63 ms |
129360 KB |
Output is correct |
40 |
Correct |
66 ms |
129228 KB |
Output is correct |
41 |
Correct |
53 ms |
129416 KB |
Output is correct |
42 |
Correct |
53 ms |
129360 KB |
Output is correct |
43 |
Correct |
57 ms |
129408 KB |
Output is correct |
44 |
Correct |
51 ms |
129280 KB |
Output is correct |
45 |
Correct |
79 ms |
129364 KB |
Output is correct |
46 |
Correct |
55 ms |
129372 KB |
Output is correct |
47 |
Correct |
54 ms |
129264 KB |
Output is correct |
48 |
Correct |
56 ms |
129360 KB |
Output is correct |
49 |
Correct |
78 ms |
129364 KB |
Output is correct |
50 |
Correct |
52 ms |
129400 KB |
Output is correct |
51 |
Correct |
53 ms |
129364 KB |
Output is correct |
52 |
Correct |
52 ms |
129360 KB |
Output is correct |
53 |
Correct |
61 ms |
129316 KB |
Output is correct |
54 |
Correct |
54 ms |
129476 KB |
Output is correct |
55 |
Correct |
64 ms |
129416 KB |
Output is correct |
56 |
Correct |
55 ms |
129248 KB |
Output is correct |
57 |
Correct |
88 ms |
129368 KB |
Output is correct |
58 |
Correct |
59 ms |
129380 KB |
Output is correct |
59 |
Correct |
86 ms |
129484 KB |
Output is correct |
60 |
Correct |
89 ms |
129372 KB |
Output is correct |
61 |
Correct |
93 ms |
129396 KB |
Output is correct |
62 |
Correct |
80 ms |
129408 KB |
Output is correct |
63 |
Correct |
82 ms |
129476 KB |
Output is correct |
64 |
Correct |
80 ms |
129484 KB |
Output is correct |
65 |
Correct |
85 ms |
129464 KB |
Output is correct |
66 |
Correct |
84 ms |
129360 KB |
Output is correct |
67 |
Correct |
79 ms |
129364 KB |
Output is correct |
68 |
Correct |
76 ms |
129364 KB |
Output is correct |
69 |
Correct |
78 ms |
129364 KB |
Output is correct |
70 |
Correct |
71 ms |
129364 KB |
Output is correct |
71 |
Correct |
88 ms |
129352 KB |
Output is correct |
72 |
Correct |
71 ms |
129244 KB |
Output is correct |
73 |
Correct |
85 ms |
129364 KB |
Output is correct |
74 |
Correct |
76 ms |
129468 KB |
Output is correct |
75 |
Correct |
86 ms |
129256 KB |
Output is correct |
76 |
Correct |
77 ms |
129364 KB |
Output is correct |
77 |
Correct |
98 ms |
129364 KB |
Output is correct |
78 |
Correct |
88 ms |
129292 KB |
Output is correct |
79 |
Correct |
73 ms |
129484 KB |
Output is correct |
80 |
Correct |
74 ms |
129364 KB |
Output is correct |
81 |
Correct |
74 ms |
129480 KB |
Output is correct |
82 |
Correct |
81 ms |
129360 KB |
Output is correct |
83 |
Correct |
92 ms |
129356 KB |
Output is correct |
84 |
Correct |
86 ms |
129364 KB |
Output is correct |
85 |
Correct |
80 ms |
129264 KB |
Output is correct |
86 |
Correct |
90 ms |
129360 KB |
Output is correct |
87 |
Correct |
79 ms |
129360 KB |
Output is correct |
88 |
Correct |
82 ms |
129364 KB |
Output is correct |
89 |
Correct |
87 ms |
129268 KB |
Output is correct |
90 |
Correct |
90 ms |
129364 KB |
Output is correct |
91 |
Correct |
74 ms |
129412 KB |
Output is correct |
92 |
Correct |
82 ms |
129360 KB |
Output is correct |
93 |
Correct |
108 ms |
129480 KB |
Output is correct |