#include<iostream>
#include<cstring>
#include<vector>
#define int long long
using namespace std;
//讀: 5 想1~3: 8min 實作40min
int dp[205][205][2][205];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(dp, -1ll, sizeof(dp));
//cout << dp[200][200][0][200] << "\n";
int n, l;
cin >> n >> l;
vector<int>x(n+1), t(n+1);
x[0] = t[0] = 0ll;
for (int i = 1 ; i <= n ; i++) cin >> x[i];
for (int i = 1 ; i <= n ; i++) cin >> t[i];
dp[0][0][0][0] = dp[0][0][1][0] = 0ll;
n++;
int ans= 0;
for (int k = 0 ; k <= 205 ; k++) {//time
for (int i = 0 ; i < n ; i++) {//left
for (int j = n-1 ; j >= 0 ; j--) {//right
for (int p = 0 ; p <= 1 ; p++) {
if (dp[i][j][p][k] == -1ll) {
continue;
}
if ((i + 1) % n == j) {
if (dp[i][j][p][k] > ans)ans = dp[i][j][p][k];
continue;
}
int pos = (p == 0 ? x[i] : x[j]), next;
next = (i+1);
int cost = k + (x[next] - pos + l) % l;
dp[next][j][0][cost] = max(dp[next][j][0][cost], dp[i][j][p][k] + (cost <= t[next]));
next = (j==0 ? n-1 : j-1);
cost = k + (pos - x[next] + l) % l;
dp[i][next][1][cost] = max(dp[i][next][1][cost], dp[i][j][p][k] + (cost <= t[next]));
}
}
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
135260 KB |
Output is correct |
2 |
Correct |
16 ms |
135092 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135212 KB |
Output is correct |
6 |
Correct |
17 ms |
135328 KB |
Output is correct |
7 |
Correct |
17 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135260 KB |
Output is correct |
10 |
Correct |
16 ms |
135256 KB |
Output is correct |
11 |
Correct |
16 ms |
135260 KB |
Output is correct |
12 |
Correct |
17 ms |
135248 KB |
Output is correct |
13 |
Correct |
17 ms |
135268 KB |
Output is correct |
14 |
Correct |
17 ms |
135188 KB |
Output is correct |
15 |
Correct |
16 ms |
135268 KB |
Output is correct |
16 |
Correct |
16 ms |
135220 KB |
Output is correct |
17 |
Correct |
16 ms |
135260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
135260 KB |
Output is correct |
2 |
Correct |
16 ms |
135092 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135212 KB |
Output is correct |
6 |
Correct |
17 ms |
135328 KB |
Output is correct |
7 |
Correct |
17 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135260 KB |
Output is correct |
10 |
Correct |
16 ms |
135256 KB |
Output is correct |
11 |
Correct |
16 ms |
135260 KB |
Output is correct |
12 |
Correct |
17 ms |
135248 KB |
Output is correct |
13 |
Correct |
17 ms |
135268 KB |
Output is correct |
14 |
Correct |
17 ms |
135188 KB |
Output is correct |
15 |
Correct |
16 ms |
135268 KB |
Output is correct |
16 |
Correct |
16 ms |
135220 KB |
Output is correct |
17 |
Correct |
16 ms |
135260 KB |
Output is correct |
18 |
Incorrect |
17 ms |
135260 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
135260 KB |
Output is correct |
2 |
Correct |
16 ms |
135092 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135212 KB |
Output is correct |
6 |
Correct |
17 ms |
135328 KB |
Output is correct |
7 |
Correct |
17 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135260 KB |
Output is correct |
10 |
Correct |
16 ms |
135256 KB |
Output is correct |
11 |
Correct |
16 ms |
135260 KB |
Output is correct |
12 |
Correct |
17 ms |
135248 KB |
Output is correct |
13 |
Correct |
17 ms |
135268 KB |
Output is correct |
14 |
Correct |
17 ms |
135188 KB |
Output is correct |
15 |
Correct |
16 ms |
135268 KB |
Output is correct |
16 |
Correct |
16 ms |
135220 KB |
Output is correct |
17 |
Correct |
16 ms |
135260 KB |
Output is correct |
18 |
Correct |
106 ms |
135308 KB |
Output is correct |
19 |
Correct |
74 ms |
135136 KB |
Output is correct |
20 |
Correct |
43 ms |
135260 KB |
Output is correct |
21 |
Correct |
63 ms |
135260 KB |
Output is correct |
22 |
Correct |
80 ms |
135260 KB |
Output is correct |
23 |
Correct |
38 ms |
135260 KB |
Output is correct |
24 |
Correct |
32 ms |
135260 KB |
Output is correct |
25 |
Correct |
42 ms |
135304 KB |
Output is correct |
26 |
Correct |
28 ms |
135272 KB |
Output is correct |
27 |
Correct |
39 ms |
135260 KB |
Output is correct |
28 |
Correct |
31 ms |
135260 KB |
Output is correct |
29 |
Correct |
41 ms |
135260 KB |
Output is correct |
30 |
Correct |
33 ms |
135260 KB |
Output is correct |
31 |
Incorrect |
38 ms |
135260 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
135260 KB |
Output is correct |
2 |
Correct |
16 ms |
135092 KB |
Output is correct |
3 |
Correct |
16 ms |
135260 KB |
Output is correct |
4 |
Correct |
16 ms |
135260 KB |
Output is correct |
5 |
Correct |
16 ms |
135212 KB |
Output is correct |
6 |
Correct |
17 ms |
135328 KB |
Output is correct |
7 |
Correct |
17 ms |
135260 KB |
Output is correct |
8 |
Correct |
16 ms |
135260 KB |
Output is correct |
9 |
Correct |
16 ms |
135260 KB |
Output is correct |
10 |
Correct |
16 ms |
135256 KB |
Output is correct |
11 |
Correct |
16 ms |
135260 KB |
Output is correct |
12 |
Correct |
17 ms |
135248 KB |
Output is correct |
13 |
Correct |
17 ms |
135268 KB |
Output is correct |
14 |
Correct |
17 ms |
135188 KB |
Output is correct |
15 |
Correct |
16 ms |
135268 KB |
Output is correct |
16 |
Correct |
16 ms |
135220 KB |
Output is correct |
17 |
Correct |
16 ms |
135260 KB |
Output is correct |
18 |
Incorrect |
17 ms |
135260 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |