#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
template<class T>
inline bool asMn(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T &a, const T &b) { return a < b ? a = b, true : false; }
inline int nxt(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int prv(int i, int n) { return !i ? n - 1 : i - 1; }
const int inf = 1e9 + 100;
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef FourLeafClover
freopen("input", "r", stdin);
#endif // FourLeafCLover
int n, l; cin >> n >> l;
vector<int> x(n), t(n);
for (auto &i : x) cin >> i;
for (auto &i : t) cin >> i;
vector<vector<vector<array<int, 2> > > > f(n + 1, vector<vector<array<int, 2> > >(n + 1, vector<array<int, 2> >(n + 1, array<int, 2>{ inf, inf } ) ) );
f[0][n][n][0] = 0;
for (int nStamp = 0; nStamp < n; ++nStamp) {
for (int i = n; ~i; --i) {
for (int j = n, cnt = 0; (j == n && !cnt) || j < i; j = nxt(j, n + 1), cnt += (j == n) ) {
for (int side = 0; side < 2; ++side) if (f[nStamp][i][j][side] < inf) {
int prvI = prv(i, n + 1), nxtJ = nxt(j, n + 1);
if (!side) {
if (prvI != j) asMn(f[nStamp + (f[nStamp][i][j][side] + (i == n ? l : x[i]) - x[prvI] <= t[prvI])][prvI][j][0],
f[nStamp][i][j][side] + (i == n ? l : x[i]) - x[prvI]);
if (nxtJ != i) asMn(f[nStamp + (f[nStamp][i][j][side] + (i == n ? 0 : l - x[i]) + x[nxtJ] <= t[nxtJ])][i][nxtJ][1],
f[nStamp][i][j][side] + (i == n ? 0 : l - x[i]) + x[nxtJ]);
}
else {
if (prvI != j) asMn(f[nStamp + (f[nStamp][i][j][side] + (j == n ? 0 : x[j]) + l - x[prvI] <= t[prvI])][prvI][j][0],
f[nStamp][i][j][side] + (j == n ? 0 : x[j]) + l - x[prvI]);
if (nxtJ != i) asMn(f[nStamp + (f[nStamp][i][j][side] + x[nxtJ] - (j == n ? 0 : x[j]) <= t[nxtJ])][i][nxtJ][1],
f[nStamp][i][j][side] + x[nxtJ] - (j == n ? 0 : x[j]));
}
}
}
}
}
int ans = 0;
for (int nStamp = 1; nStamp <= n; ++nStamp) {
for (int i = n; ~i; --i) {
for (int j = n, cnt = 0; (j == n && !cnt) || j < i; j = nxt(j, n + 1), cnt += (j == n) ) {
for (int side = 0; side < 2; ++side) if (f[nStamp][i][j][side] < inf) ans = nStamp;
}
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
372 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
372 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
380 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
380 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
372 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
93 ms |
47480 KB |
Output is correct |
19 |
Correct |
48 ms |
22792 KB |
Output is correct |
20 |
Correct |
21 ms |
9080 KB |
Output is correct |
21 |
Correct |
42 ms |
20860 KB |
Output is correct |
22 |
Correct |
61 ms |
30456 KB |
Output is correct |
23 |
Correct |
22 ms |
7288 KB |
Output is correct |
24 |
Correct |
12 ms |
5112 KB |
Output is correct |
25 |
Correct |
20 ms |
6904 KB |
Output is correct |
26 |
Correct |
7 ms |
1912 KB |
Output is correct |
27 |
Correct |
21 ms |
7416 KB |
Output is correct |
28 |
Correct |
12 ms |
4600 KB |
Output is correct |
29 |
Correct |
20 ms |
7672 KB |
Output is correct |
30 |
Correct |
12 ms |
5368 KB |
Output is correct |
31 |
Correct |
18 ms |
6904 KB |
Output is correct |
32 |
Correct |
9 ms |
2808 KB |
Output is correct |
33 |
Correct |
18 ms |
6904 KB |
Output is correct |
34 |
Correct |
7 ms |
1784 KB |
Output is correct |
35 |
Correct |
15 ms |
6776 KB |
Output is correct |
36 |
Correct |
8 ms |
2424 KB |
Output is correct |
37 |
Correct |
20 ms |
7416 KB |
Output is correct |
38 |
Correct |
10 ms |
3192 KB |
Output is correct |
39 |
Correct |
16 ms |
7928 KB |
Output is correct |
40 |
Correct |
10 ms |
3704 KB |
Output is correct |
41 |
Correct |
130 ms |
65016 KB |
Output is correct |
42 |
Correct |
55 ms |
36220 KB |
Output is correct |
43 |
Correct |
132 ms |
65016 KB |
Output is correct |
44 |
Correct |
46 ms |
35320 KB |
Output is correct |
45 |
Correct |
137 ms |
64888 KB |
Output is correct |
46 |
Correct |
45 ms |
36216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
372 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
380 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
380 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
93 ms |
47480 KB |
Output is correct |
37 |
Correct |
48 ms |
22792 KB |
Output is correct |
38 |
Correct |
21 ms |
9080 KB |
Output is correct |
39 |
Correct |
42 ms |
20860 KB |
Output is correct |
40 |
Correct |
61 ms |
30456 KB |
Output is correct |
41 |
Correct |
22 ms |
7288 KB |
Output is correct |
42 |
Correct |
12 ms |
5112 KB |
Output is correct |
43 |
Correct |
20 ms |
6904 KB |
Output is correct |
44 |
Correct |
7 ms |
1912 KB |
Output is correct |
45 |
Correct |
21 ms |
7416 KB |
Output is correct |
46 |
Correct |
12 ms |
4600 KB |
Output is correct |
47 |
Correct |
20 ms |
7672 KB |
Output is correct |
48 |
Correct |
12 ms |
5368 KB |
Output is correct |
49 |
Correct |
18 ms |
6904 KB |
Output is correct |
50 |
Correct |
9 ms |
2808 KB |
Output is correct |
51 |
Correct |
18 ms |
6904 KB |
Output is correct |
52 |
Correct |
7 ms |
1784 KB |
Output is correct |
53 |
Correct |
15 ms |
6776 KB |
Output is correct |
54 |
Correct |
8 ms |
2424 KB |
Output is correct |
55 |
Correct |
20 ms |
7416 KB |
Output is correct |
56 |
Correct |
10 ms |
3192 KB |
Output is correct |
57 |
Correct |
16 ms |
7928 KB |
Output is correct |
58 |
Correct |
10 ms |
3704 KB |
Output is correct |
59 |
Correct |
130 ms |
65016 KB |
Output is correct |
60 |
Correct |
55 ms |
36220 KB |
Output is correct |
61 |
Correct |
132 ms |
65016 KB |
Output is correct |
62 |
Correct |
46 ms |
35320 KB |
Output is correct |
63 |
Correct |
137 ms |
64888 KB |
Output is correct |
64 |
Correct |
45 ms |
36216 KB |
Output is correct |
65 |
Correct |
70 ms |
55672 KB |
Output is correct |
66 |
Correct |
64 ms |
49144 KB |
Output is correct |
67 |
Correct |
61 ms |
45944 KB |
Output is correct |
68 |
Correct |
67 ms |
40568 KB |
Output is correct |
69 |
Correct |
69 ms |
54520 KB |
Output is correct |
70 |
Correct |
68 ms |
51192 KB |
Output is correct |
71 |
Correct |
63 ms |
52344 KB |
Output is correct |
72 |
Correct |
72 ms |
52956 KB |
Output is correct |
73 |
Correct |
56 ms |
47484 KB |
Output is correct |
74 |
Correct |
56 ms |
43000 KB |
Output is correct |
75 |
Correct |
59 ms |
49656 KB |
Output is correct |
76 |
Correct |
93 ms |
61048 KB |
Output is correct |
77 |
Correct |
74 ms |
61048 KB |
Output is correct |
78 |
Correct |
66 ms |
41592 KB |
Output is correct |
79 |
Correct |
55 ms |
43512 KB |
Output is correct |
80 |
Correct |
96 ms |
59256 KB |
Output is correct |
81 |
Correct |
56 ms |
44408 KB |
Output is correct |
82 |
Correct |
74 ms |
48248 KB |
Output is correct |
83 |
Correct |
77 ms |
64888 KB |
Output is correct |
84 |
Correct |
74 ms |
51192 KB |
Output is correct |
85 |
Correct |
68 ms |
58104 KB |
Output is correct |
86 |
Correct |
80 ms |
56312 KB |
Output is correct |
87 |
Correct |
67 ms |
49656 KB |
Output is correct |
88 |
Correct |
83 ms |
65528 KB |
Output is correct |
89 |
Correct |
79 ms |
65528 KB |
Output is correct |
90 |
Correct |
63 ms |
50680 KB |
Output is correct |
91 |
Correct |
85 ms |
65528 KB |
Output is correct |
92 |
Correct |
79 ms |
65532 KB |
Output is correct |
93 |
Correct |
76 ms |
63608 KB |
Output is correct |