Submission #684661

#TimeUsernameProblemLanguageResultExecution timeMemory
684661viciousCollecting Stamps 3 (JOI20_ho_t3)C++17
0 / 100
1 ms980 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define si second typedef pair<int,int> pi; typedef tuple<int,int,int> ti; template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) const int N = 210; const ll INF=1e18; int n,l; int a[N],t[N]; ll dp[N][N][N][2],opt[N],ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin.exceptions(ios::badbit|ios::failbit); cin >> n >> l; for (int i = 1; i <= n; ++i) cin >> a[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+1; ++k) { dp[i][j][k][0]=INF; dp[i][j][k][1]=INF; } } } a[n+1]=l; dp[0][n+1][0][0]=0; dp[0][n+1][0][1]=0; for (int i = 0; i <= n; ++i) { for (int j = n+1; j >= 1; --j) { for (int take = 1; take <= n; ++take) { if (i==0 && j==n+1) continue; if (take>n-j+i+1) continue; if (i && take) { // go to pref ll now = dp[i-1][j][take-1][0]+a[i]-a[i-1]; chmin(now, dp[i-1][j][take-1][1]+l-a[j]+a[i]); if (now <= t[i]) chmin(dp[i][j][take][0], now); else chmin(dp[i][j][take-1][0], now); } if (j<n+1 && take) { // go to suff ll now = dp[i][j+1][take-1][1]+a[j+1]-a[j]; chmin(now, dp[i][j+1][take-1][0]+l-a[j]+a[i]); if (now <= t[j]) chmin(dp[i][j][take][1], now); else chmin(dp[i][j][take-1][1], now); } } } } for (int x = 1; x <= n; ++x) { opt[x]=INF; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n+1; ++j) { chmin(opt[x],min(dp[i][j][x][0],dp[i][j][x][1])); } } if (opt[x]!=INF) ans = x; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...