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 ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 222;
const ll inf = 1e17;
const ll mod = 1e9 + 7;
const ll block = 350;
ll dp[N][N][N][2]; // dp[l][r][stamps][left/right]
ll n,L;
ll x[N], t[N];
void to_thic_cau(){
cin >> n >> L;
x[n+1] = 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 + 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] = inf;
}
}
dp[0][n+1][0][0] = 0;
for(int i = 0; i <= n + 1;i++){
for(int j = n + 1; j > i;j--){
if(i == 0 && j == n + 1) continue;
for(int k = 0; k <= n;k++){
// TH ko pick
if(i >= 1){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][0] + x[i] - x[i-1]);
if(j <= n) dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][1] + x[i] + L - x[j]);
}
if(j <= n){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][1] + x[j+1] - x[j]);
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][0] + x[i] + L - x[j]);
}
if(k == 0) continue;
// xet TH co pick (ben trai)
if(i >= 1){
if(dp[i-1][j][k-1][0] + x[i] - x[i-1] <= t[i]){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][0] + x[i] - x[i-1]);
}
if(j <= n){
if(dp[i-1][j][k-1][1] + x[i] + L - x[j] <= t[i]){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][1] + x[i] + L - x[j]);
}
}
}
if(j <= n){
if(dp[i][j+1][k-1][1] + x[j+1] - x[j] <= t[j]){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][1] + x[j+1] - x[j]);
}
if(dp[i][j+1][k-1][0] + x[i] + L - x[j] <= t[j]){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][0] + x[i] + L - x[j]);
}
}
}
}
}
ll res = 0;
for(int i = 0; i <= n;i++){
for(int j = 0; j <= n + 1;j++){
for(int k = 0; k <= n;k++){
if(dp[i][j][k][0] < inf || dp[i][j][k][1] < inf) res = max(res, k * 1ll);
}
}
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# | 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... |