#include<bits/stdc++.h>
using namespace std;
const int MX = 203;
int n, L;
int pos[MX], T[MX];
map<tuple<int,int,long long>, int>dp;
int dist(int i, int j) {
int ret = abs(pos[i]-pos[j]);
return min(ret, L-ret);
}
int solve(int i, int j, long long CLOCK) {
if(dp.count({i, j, CLOCK})) return dp[{i, j, CLOCK}];
int ret = 0;
if(i<j) {
if(i<n) ret = max(ret, solve(j, i+1, CLOCK+dist(i, j)));
else ret = max(ret, solve(j, j, CLOCK+dist(i, j)));
if(i<n) ret = max(ret, solve(i+1, j, CLOCK+dist(i, i+1)));
} else if(i>j) {
if(i>1) ret = max(ret, solve(i-1, j, CLOCK+dist(i, i-1)));
if(i>1) ret = max(ret, solve(j, i-1, CLOCK+dist(j, i)));
else ret = max(ret, solve(j, j, CLOCK+dist(j, i)));
}
ret += CLOCK<=T[i];
dp[{i, j, CLOCK}] = ret;
assert(dp.size()<=10000000);
return ret;
}
void PlayGround() {
cin>>n>>L;
for(int i=1; i<=n; ++i) {
cin>>pos[i];
}
for(int i=1; i<=n; ++i) {
cin>>T[i];
}
cout << max(solve(1, n, pos[1]), solve(n, 1, L-pos[n])) << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
11 ms |
1800 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
10 ms |
1748 KB |
Output is correct |
22 |
Correct |
1 ms |
424 KB |
Output is correct |
23 |
Correct |
22 ms |
3400 KB |
Output is correct |
24 |
Correct |
7 ms |
980 KB |
Output is correct |
25 |
Correct |
11 ms |
1848 KB |
Output is correct |
26 |
Correct |
12 ms |
1748 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
28 ms |
3316 KB |
Output is correct |
30 |
Correct |
28 ms |
3376 KB |
Output is correct |
31 |
Correct |
14 ms |
1788 KB |
Output is correct |
32 |
Correct |
6 ms |
980 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Execution timed out |
2096 ms |
128532 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
11 ms |
1800 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
596 KB |
Output is correct |
21 |
Correct |
10 ms |
1748 KB |
Output is correct |
22 |
Correct |
1 ms |
424 KB |
Output is correct |
23 |
Correct |
22 ms |
3400 KB |
Output is correct |
24 |
Correct |
7 ms |
980 KB |
Output is correct |
25 |
Correct |
11 ms |
1848 KB |
Output is correct |
26 |
Correct |
12 ms |
1748 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
28 ms |
3316 KB |
Output is correct |
30 |
Correct |
28 ms |
3376 KB |
Output is correct |
31 |
Correct |
14 ms |
1788 KB |
Output is correct |
32 |
Correct |
6 ms |
980 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Execution timed out |
2096 ms |
128532 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |