#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
namespace debug {
const int DEBUG = true;
template<class T1, class T2>
void pr(const pair<T1, T2> &x);
template<class T, size_t SZ>
void pr(const array<T, SZ> &x);
template<class T>
void pr(const vector<T> &x);
template<class T>
void pr(const set<T> &x);
template<class T1, class T2>
void pr(const map<T1, T2> &x);
template<class T>
void pr(const T &x) { if (DEBUG) cout << x; }
template<class T, class... Ts>
void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }
template<class T1, class T2>
void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
template<class T>
void prIn(const T &x) {
pr("{");
bool fst = 1;
for (auto &a : x) {
pr(fst ? "" : ", ", a), fst = 0;
}
pr("}");
}
template<class T, size_t SZ>
void pr(const array<T, SZ> &x) { prIn(x); }
template<class T>
void pr(const vector<T> &x) { prIn(x); }
template<class T>
void pr(const set<T> &x) { prIn(x); }
template<class T1, class T2>
void pr(const map<T1, T2> &x) { prIn(x); }
void ps() { pr("\n"), cout << flush; }
template<class Arg, class... Args>
void ps(const Arg &first, const Args &... rest) {
pr(first, " ");
ps(rest...);
}
}
using namespace debug;
const int MAXN = 200 + 5;
const ll INF = 1e15;
int N;
ll L;
ll dp[MAXN][MAXN][MAXN][2];
ll x[MAXN], t[MAXN];
ll dist(int l, int r) {
if (l <= r) {
return x[r] - x[l];
} else {
return L - x[l] + x[r];
}
}
int main() {
cin >> N >> L;
x[0] = 0;
t[0] = -1;
for (int i = 1; i <= N; i++) {
cin >> x[i];
}
for (int i = 1; i <= N; i++) {
cin >> t[i];
}
for (int cVal = 0; cVal <= N; cVal++) {
for (int l = 0; l <= N; l++) {
for (int r = 0; r <= N; r++) {
for (int s = 0; s < 2; s++) {
dp[cVal][l][r][s] = INF;
}
}
}
}
dp[0][0][0][0] = 0;
// we don't need to transition from state where we already have all N+1 points
for (int len = 1; len <= N; len++) {
for (int r = 0; r <= N; r++) {
int l = r - len + 1;
if (l > 0) {
continue;
}
l = (l + N + 1) % (N + 1);
for (int cVal = 0; cVal < N; cVal++) {
for (int s = 0; s < 2; s++) {
ll cCost = dp[cVal][l][r][s];
if (cCost == INF) continue;
// ps(cVal, l, r, s);
// ps(cCost);
int nL = (l - 1 + N + 1) % (N + 1);
int nR = (r + 1) % (N + 1);
if (nL != r) {
ll nCost = cCost + dist(nL, s ? r : l);
int nVal = cVal;
if (nCost <= t[nL]) {
nVal++;
}
dp[nVal][nL][r][0] = min(dp[nVal][nL][r][0], nCost);
}
if (nR != l) {
ll nCost = cCost + dist(s ? r : l, nR);
int nVal = cVal;
if (nCost <= t[nR]) {
nVal++;
}
dp[nVal][l][nR][1] = min(dp[nVal][l][nR][1], nCost);
}
}
}
}
}
int ans = 0;
for (int cVal = 0; cVal <= N; cVal++) {
for (int l = 0; l <= N; l++) {
for (int r = 0; r <= N; r++) {
for (int s = 0; s < 2; s++) {
ll cCost = dp[cVal][l][r][s];
if (cCost == INF) continue;
ans = max(ans, cVal);
}
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
764 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
280 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
764 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
280 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1016 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1016 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
6 ms |
1144 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1020 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
1140 KB |
Output is correct |
30 |
Correct |
5 ms |
1148 KB |
Output is correct |
31 |
Correct |
6 ms |
1020 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1148 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
764 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
280 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
153 ms |
105024 KB |
Output is correct |
19 |
Correct |
87 ms |
63736 KB |
Output is correct |
20 |
Correct |
44 ms |
34168 KB |
Output is correct |
21 |
Correct |
77 ms |
60152 KB |
Output is correct |
22 |
Correct |
111 ms |
77944 KB |
Output is correct |
23 |
Correct |
37 ms |
28920 KB |
Output is correct |
24 |
Correct |
24 ms |
22648 KB |
Output is correct |
25 |
Correct |
39 ms |
28280 KB |
Output is correct |
26 |
Correct |
14 ms |
10872 KB |
Output is correct |
27 |
Correct |
37 ms |
29560 KB |
Output is correct |
28 |
Correct |
25 ms |
21240 KB |
Output is correct |
29 |
Correct |
38 ms |
30200 KB |
Output is correct |
30 |
Correct |
25 ms |
23800 KB |
Output is correct |
31 |
Correct |
34 ms |
28280 KB |
Output is correct |
32 |
Correct |
17 ms |
14840 KB |
Output is correct |
33 |
Correct |
40 ms |
28408 KB |
Output is correct |
34 |
Correct |
12 ms |
10232 KB |
Output is correct |
35 |
Correct |
32 ms |
27768 KB |
Output is correct |
36 |
Correct |
16 ms |
13176 KB |
Output is correct |
37 |
Correct |
37 ms |
29560 KB |
Output is correct |
38 |
Correct |
18 ms |
16248 KB |
Output is correct |
39 |
Correct |
32 ms |
30840 KB |
Output is correct |
40 |
Correct |
19 ms |
18168 KB |
Output is correct |
41 |
Correct |
257 ms |
129656 KB |
Output is correct |
42 |
Correct |
102 ms |
87160 KB |
Output is correct |
43 |
Correct |
241 ms |
129520 KB |
Output is correct |
44 |
Correct |
106 ms |
86264 KB |
Output is correct |
45 |
Correct |
232 ms |
129528 KB |
Output is correct |
46 |
Correct |
87 ms |
87160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
764 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
5 ms |
280 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1016 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1016 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
6 ms |
1144 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1020 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
1140 KB |
Output is correct |
30 |
Correct |
5 ms |
1148 KB |
Output is correct |
31 |
Correct |
6 ms |
1020 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1148 KB |
Output is correct |
34 |
Correct |
5 ms |
1144 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
36 |
Correct |
153 ms |
105024 KB |
Output is correct |
37 |
Correct |
87 ms |
63736 KB |
Output is correct |
38 |
Correct |
44 ms |
34168 KB |
Output is correct |
39 |
Correct |
77 ms |
60152 KB |
Output is correct |
40 |
Correct |
111 ms |
77944 KB |
Output is correct |
41 |
Correct |
37 ms |
28920 KB |
Output is correct |
42 |
Correct |
24 ms |
22648 KB |
Output is correct |
43 |
Correct |
39 ms |
28280 KB |
Output is correct |
44 |
Correct |
14 ms |
10872 KB |
Output is correct |
45 |
Correct |
37 ms |
29560 KB |
Output is correct |
46 |
Correct |
25 ms |
21240 KB |
Output is correct |
47 |
Correct |
38 ms |
30200 KB |
Output is correct |
48 |
Correct |
25 ms |
23800 KB |
Output is correct |
49 |
Correct |
34 ms |
28280 KB |
Output is correct |
50 |
Correct |
17 ms |
14840 KB |
Output is correct |
51 |
Correct |
40 ms |
28408 KB |
Output is correct |
52 |
Correct |
12 ms |
10232 KB |
Output is correct |
53 |
Correct |
32 ms |
27768 KB |
Output is correct |
54 |
Correct |
16 ms |
13176 KB |
Output is correct |
55 |
Correct |
37 ms |
29560 KB |
Output is correct |
56 |
Correct |
18 ms |
16248 KB |
Output is correct |
57 |
Correct |
32 ms |
30840 KB |
Output is correct |
58 |
Correct |
19 ms |
18168 KB |
Output is correct |
59 |
Correct |
257 ms |
129656 KB |
Output is correct |
60 |
Correct |
102 ms |
87160 KB |
Output is correct |
61 |
Correct |
241 ms |
129520 KB |
Output is correct |
62 |
Correct |
106 ms |
86264 KB |
Output is correct |
63 |
Correct |
232 ms |
129528 KB |
Output is correct |
64 |
Correct |
87 ms |
87160 KB |
Output is correct |
65 |
Correct |
196 ms |
116856 KB |
Output is correct |
66 |
Correct |
181 ms |
107256 KB |
Output is correct |
67 |
Correct |
174 ms |
102648 KB |
Output is correct |
68 |
Correct |
141 ms |
94840 KB |
Output is correct |
69 |
Correct |
195 ms |
115832 KB |
Output is correct |
70 |
Correct |
197 ms |
110840 KB |
Output is correct |
71 |
Correct |
171 ms |
111992 KB |
Output is correct |
72 |
Correct |
220 ms |
113356 KB |
Output is correct |
73 |
Correct |
146 ms |
104952 KB |
Output is correct |
74 |
Correct |
161 ms |
98168 KB |
Output is correct |
75 |
Correct |
178 ms |
108536 KB |
Output is correct |
76 |
Correct |
221 ms |
124408 KB |
Output is correct |
77 |
Correct |
241 ms |
124280 KB |
Output is correct |
78 |
Correct |
184 ms |
95864 KB |
Output is correct |
79 |
Correct |
170 ms |
99192 KB |
Output is correct |
80 |
Correct |
279 ms |
121848 KB |
Output is correct |
81 |
Correct |
159 ms |
100472 KB |
Output is correct |
82 |
Correct |
145 ms |
106104 KB |
Output is correct |
83 |
Correct |
247 ms |
129520 KB |
Output is correct |
84 |
Correct |
176 ms |
110840 KB |
Output is correct |
85 |
Correct |
199 ms |
120568 KB |
Output is correct |
86 |
Correct |
163 ms |
118136 KB |
Output is correct |
87 |
Correct |
175 ms |
108536 KB |
Output is correct |
88 |
Correct |
309 ms |
130808 KB |
Output is correct |
89 |
Correct |
288 ms |
130936 KB |
Output is correct |
90 |
Correct |
126 ms |
109816 KB |
Output is correct |
91 |
Correct |
258 ms |
130936 KB |
Output is correct |
92 |
Correct |
225 ms |
130808 KB |
Output is correct |
93 |
Correct |
169 ms |
128120 KB |
Output is correct |