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;
/* sorry, this is the bare minimum :'( */
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second
#define rep(x,n) for(int x = 0; x < n; ++x)
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const int N = 203;
const int inf = 1e9 + 69;
int X[N], L, n, T[N];
int dp[N][N][N][2];
void chkmin(int &x, int y) {
x = min(x, y);
}
int main(int argc, char const *argv[])
{
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
cin >> n >> L;
for(int i = 1; i <= n; ++i) {
cin >> X[i];
}
X[0] = 0;
X[n+1] = L;
for(int i = 1; i <= n; ++i) {
cin >> T[i];
}
rep(i, N) rep(j, N) rep(k, N) rep(l, 2) dp[i][j][k][l] = inf;
dp[0][n+1][0][1] = dp[0][n+1][0][0] = 0;
for(int len = n+1; len > 1; --len) {
for(int i = 0, j = i+len; j <= n+1; ++i, ++j) {
for(int k = 0; k <= n; ++k) {
chkmin(
dp[i+1][j][k+(dp[i][j][k][0] + X[i+1] - X[i] <= T[i+1])][0],
dp[i][j][k][0] + X[i+1] - X[i]
);
if(X[i+1] - X[i] < 0) debug(i, X[i+1] - X[i]);
chkmin(
dp[i][j-1][k+(dp[i][j][k][0] + L-(X[j-1] - X[i]) <= T[j-1])][1],
dp[i][j][k][0] + L-(X[j-1] - X[i])
);
if(L-(X[j-1] - X[i]) < 0) debug(i, j, L-(X[j-1] - X[i]));
chkmin(
dp[i+1][j][k+(dp[i][j][k][1] + L-(X[j] - X[i+1]) <= T[i+1])][0],
dp[i][j][k][1] + L-(X[j] - X[i+1])
);
if(L-(X[j] - X[i+1]) < 0) debug(i, j, L-(X[j] - X[i+1]));
chkmin(
dp[i][j-1][k+(dp[i][j][k][1] + X[j] - X[j-1] <= T[j-1])][1],
dp[i][j][k][1] + X[j] - X[j-1]
);
if(X[j] - X[j-1] < 0) debug(j, X[j] - X[j-1]);
}
}
}
int ans = 0;
for(int i = 0; i <= n+1; ++i) {
for(int j = i+1; j <= n+1; ++j) {
for(int k = 0; k <= n; ++k) {
if(dp[i][j][k][0] < inf or dp[i][j][k][1] < inf) {
debug(i, j, k, dp[i][j][k][0], dp[i][j][k][1]);
ans = max(ans, k);
}
}
}
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
ho_t3.cpp: In function 'int main(int, const char**)':
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 42
| ^~
ho_t3.cpp:96:31: note: in expansion of macro 'debug'
96 | if(X[i+1] - X[i] < 0) debug(i, X[i+1] - X[i]);
| ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 42
| ^~
ho_t3.cpp:101:35: note: in expansion of macro 'debug'
101 | if(L-(X[j-1] - X[i]) < 0) debug(i, j, L-(X[j-1] - X[i]));
| ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 42
| ^~
ho_t3.cpp:106:35: note: in expansion of macro 'debug'
106 | if(L-(X[j] - X[i+1]) < 0) debug(i, j, L-(X[j] - X[i+1]));
| ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 42
| ^~
ho_t3.cpp:111:31: note: in expansion of macro 'debug'
111 | if(X[j] - X[j-1] < 0) debug(j, X[j] - X[j-1]);
| ^~~~~
ho_t3.cpp:57:20: warning: statement has no effect [-Wunused-value]
57 | #define debug(...) 42
| ^~
ho_t3.cpp:120:11: note: in expansion of macro 'debug'
120 | debug(i, j, k, dp[i][j][k][0], dp[i][j][k][1]);
| ^~~~~
# | 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... |