Submission #795394

#TimeUsernameProblemLanguageResultExecution timeMemory
795394Theo830Collecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
93 ms135232 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin>>n; ll l; cin>>l; ll x[n+2]; x[0] = 0; f(i,1,n+1){ cin>>x[i]; } x[n+1] = l; ll t[n+2]; t[0] = t[n+1] = -1; f(i,1,n+1){ cin>>t[i]; } ll dp[205][205][205][2]; f(i,0,n+5){ f(j,0,n+5){ f(k,0,n+5){ f(u,0,2){ dp[i][j][k][u] = INF; } } } } ll ans = 0; f(i,0,n+1){ f(j,0,n+1){ if(i + j <= n){ f(k,0,n+1){ if(k == 0){ dp[i][j][k][0] = dp[i][j][k][1] = l - x[n+1-i] + x[j]; } dp[i][j+1][k][0] = min({dp[i][j+1][k][0],dp[i][j][k][0] + x[j+1] - x[j],dp[i][j][k][1] + l - x[n+1-i] + x[j+1]}); dp[i+1][j][k][1] = min({dp[i+1][j][k][1],dp[i][j][k][1] + x[n+1-i] - x[n-i],dp[i][j][k][0] + x[j] + l - x[n-i]}); if(min(dp[i][j][k][0] + x[j+1] - x[j],dp[i][j][k][1] + l - x[n+1-i] + x[j+1]) <= t[j+1]){ dp[i][j+1][k+1][0] = min({dp[i][j+1][k+1][0],dp[i][j][k][0] + x[j+1] - x[j],dp[i][j][k][1] + l - x[n+1-i] + x[j+1]}); } if(min(dp[i][j][k][1] + x[n+1-i] - x[n-i],dp[i][j][k][0] + x[j] + l - x[n-i]) <= t[n-i]){ dp[i+1][j][k+1][1] = min({dp[i+1][j][k+1][1],dp[i][j][k][1] + x[n+1-i] - x[n-i],dp[i][j][k][0] + x[j] + l - x[n-i]}); } f(u,0,2){ if(dp[i][j][k][u] < INF){ ans = max(ans,k); } } } } } } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...