# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
629985 | colossal_pepe | Collecting Stamps 3 (JOI20_ho_t3) | C++17 | 0 ms | 0 KiB |
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 <iostream>
#include <map>
using namespace std;
using ll = long long;
int n, l;
ll x[205], t[205];
map<ll, int> dp[205][205];
ll dist(int x1, int x2) {
if (x1 > x2) swap(x1, x2);
return min(x2 - x1, l - x2 + x1)
}
int solve(int i, int j, ll time_passed) {
if (i == j) return 0;
if (dp[i][j].count(time_passed)) return dp[i][j][time_passed];
int cur = i, l = min(i, j), r = max(i, j);
int ans = solve(l + 1, r, dist(x[cur], x[l + 1]) + time_passed) + (dist(x[cur], x[l + 1]) + time_passed <= t[l + 1]);
ans = max(ans, solve(r - 1, l, dist(x[cur], x[r - 1]) + time_passed) + (dist(x[cur], x[r - 1]) + time_passed <= t[r - 1]));
dp[i][j][time_passed] = ans;
return ans;
}
int main() {
cin >> n >> l;
for (int i = 0; i < n; i++) {
cin >> x[i];
}
for (int i = 0; i < n; i++) {
cin >> t[i];
}
cout << solve(0, n - 1, 0) << '\n';
return 0;
}