Submission #910127

#TimeUsernameProblemLanguageResultExecution timeMemory
910127OAleksaCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
70 ms140160 KiB
#include <bits/stdc++.h> //ako ovaj vaso daso misli da me pobedjuje..... using namespace std; #define int long long #define f first #define s second const int N = 210; const int inf = 1e18; int n, l, x[N], t[N], dp[N][N][N][2]; //prvih i, poslednjih j, pokupio, i/j signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n >> l; for (int i = 1;i <= n;i++) { cin >> x[i]; } for (int i = 1;i <= n;i++) { cin >> t[i]; } x[n + 1] = l; for (int i = 0;i <= n;i++) { for (int j = 0;j <= n;j++) { for (int k = 0;k <= n;k++) dp[i][j][k][0] = dp[i][j][k][1] = inf; } } dp[0][0][0][0] = dp[0][0][0][1] = 0; int ans = 0; for (int cnt = 0;cnt <= n;cnt++) { for (int i = 0;i <= n;i++) { for (int j = 0;j <= n;j++) { if (i + j > n) break; if (i > 0) { dp[i][j][cnt][0] = min(dp[i][j][cnt][0], dp[i - 1][j][cnt][0] + x[i] - x[i - 1]); dp[i][j][cnt][0] = min(dp[i][j][cnt][0], dp[i - 1][j][cnt][1] + x[i] + (l - x[n - j + 1])); if (cnt > 0) { int time1 = dp[i - 1][j][cnt - 1][0] + x[i] - x[i - 1]; int time2 = dp[i - 1][j][cnt - 1][1] + x[i] + (l - x[n - j + 1]); int time = min(time1, time2); if (time <= t[i]) dp[i][j][cnt][0] = min(dp[i][j][cnt][0], time); } } if (j > 0) { dp[i][j][cnt][1] = min(dp[i][j][cnt][1], dp[i][j - 1][cnt][1] + x[n - j + 2] - x[n - j + 1]); dp[i][j][cnt][1] = min(dp[i][j][cnt][1], dp[i][j - 1][cnt][0] + x[i] + (l - x[n - j + 1])); if (cnt > 0) { int time1 = dp[i][j - 1][cnt - 1][1] + x[n - j + 2] - x[n - j + 1]; int time2 = dp[i][j - 1][cnt - 1][0] + x[i] + (l - x[n - j + 1]); int time = min(time1, time2); if (time <= t[n - j + 1]) dp[i][j][cnt][1] = min(dp[i][j][cnt][1], time); } } if (dp[i][j][cnt][0] != inf || dp[i][j][cnt][1] != inf) ans = cnt; } } } 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...