This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
typedef unsigned int unt;
const int N = 210;
int n, L, odp;
unt X[N];
unt T[N];
unt dp[N][N][N][2];
int main() {
scanf("%d%d", &n, &L);
for (int i = 1; i <= n; ++i) {
scanf("%d", &X[i]);
}
X[n + 1] = L;
for (int i = 1; i <= n; ++i) {
scanf("%d", &T[i]);
}
for (int i = 0; i <= n + 1; ++i) {
for (int j = 0; j <= n + 1; ++j) {
for (int k = 0; k <= n; ++k) {
dp[i][j][k][0] = dp[i][j][k][1] = 1e9 + 7;
}
}
}
dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
for (int l = 0; l <= n; ++l) {
for (int r = n + 1; r > l + 1; --r) {
for (int k = 0; k <= n; ++k) {
dp[l][r][k][0] = min(dp[l][r][k][0], dp[l][r][k][1] + L - X[r] + X[l]);
dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r][k][0] + L - X[r] + X[l]);
//~ debug(l, r, k, dp[l][r][k][0], dp[l][r][k][1]);
if (dp[l][r][k][0] + X[l + 1] - X[l] <= T[l + 1]) {
odp = max(odp, k + 1);
dp[l + 1][r][k + 1][0] = min(dp[l + 1][r][k + 1][0], dp[l][r][k][0] + X[l + 1] - X[l]);
}
else {
dp[l + 1][r][k][0] = min(dp[l + 1][r][k][0], dp[l][r][k][0] + X[l + 1] - X[l]);
}
if (dp[l][r][k][1] + X[r] - X[r - 1] <= T[r - 1]) {
odp = max(odp, k + 1);
dp[l][r - 1][k + 1][1] = min(dp[l][r - 1][k + 1][1], dp[l][r][k][1] + X[r] - X[r - 1]);
}
else {
dp[l][r - 1][k][1] = min(dp[l][r - 1][k][1], dp[l][r][k][1] + X[r] - X[r - 1]);
}
}
}
}
printf("%d\n", odp);
return 0;
}
Compilation message (stderr)
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%d%d", &n, &L);
| ~~~~~^~~~~~~~~~~~~~~~
ho_t3.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | scanf("%d", &X[i]);
| ~~~~~^~~~~~~~~~~~~
ho_t3.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d", &T[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |