This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define cerr if (false) cout
using ll = long long;
const int N = 220;
const ll INF = 1e18;
int n, L;
int x[N];
int t[N];
ll dp[N][N][N][2];
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
cin >> n >> L;
for (int i = 1; i <= n; i++)
cin >> x[i];
for (int i = 1; i <= n; i++)
cin >> t[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= n; k++)
dp[i][j][k][0] = INF,
dp[i][j][k][1] = INF;
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
for (int k = 0; k < n; k++) {
for (int s = 0; s < n; s++) {
for (int l = 0; l <= s; l++) {
int r = (l + n + 1 - s) % (n + 1);
cerr << l << ' ' << r << endl;
ll time, k_new;
time = dp[l][r][k][0] + x[l + 1] - x[l];
k_new = k + (time <= t[l + 1]);
dp[l + 1][r][k_new][0] = min(dp[l + 1][r][k_new][0], time);
cerr << "one\n";
time = dp[l][r][k][1] + x[l + 1] + (L - x[r]) % L;
k_new = k + (time <= t[l + 1]);
dp[l + 1][r][k_new][0] = min(dp[l + 1][r][k_new][0], time);
cerr << "two\n";
int r1 = (r + n) % (n + 1);
time = dp[l][r][k][0] + x[l] + L - x[r1];
k_new = k + (time <= t[r1]);
dp[l][r1][k_new][1] = min(dp[l][r1][k_new][1], time);
cerr << "three\n";
time = dp[l][r][k][1] + (x[r] - x[r1] + L) % L;
k_new = k + (time <= t[r1]);
dp[l][r1][k_new][1] = min(dp[l][r1][k_new][1], time);
cerr << "four\n";
}
}
}
for (int k = n; k >= 0; k--) {
for (int i = 0; i <= n; i++) {
if (dp[i][(i + 1) % (n + 1)][k][0] != INF) {
cout << k;
return 0;
}
if (dp[i][(i + 1) % (n + 1)][k][1] != INF) {
cout << k;
return 0;
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |