Submission #577717

#TimeUsernameProblemLanguageResultExecution timeMemory
577717JomnoiCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
254 ms132868 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 205; const long long llINF = 1e18 + 7; int X[MAX_N], T[MAX_N]; long long dp1[MAX_N][MAX_N][MAX_N], dp2[MAX_N][MAX_N][MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, L; 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 k = 0; k <= N; k++) { for(int i = 0; i <= N + 1; i++) { for(int j = 0; j <= N + 1; j++) { dp1[i][j][k] = llINF; dp2[i][j][k] = llINF; } } } int ans = 0; dp1[0][N + 1][0] = dp2[0][N + 1][0] = 0; for(int k = 0; k <= N; k++) { for(int i = 0; i <= N; i++) { for(int j = N + 1; j >= i + 1; j--) { if(i - 1 >= 0) { if(k - 1 >= 0 and dp1[i - 1][j][k - 1] + X[i] - X[i - 1] <= T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k - 1] + X[i] - X[i - 1]); } if(dp1[i - 1][j][k] + X[i] - X[i - 1] > T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k] + X[i] - X[i - 1]); } if(k - 1 >= 0 and dp2[i - 1][j][k - 1] + (L - X[j]) + X[i] <= T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k - 1] + (L - X[j]) + X[i]); } if(dp2[i - 1][j][k] + (L - X[j]) + X[i] > T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k] + (L - X[j]) + X[i]); } } if(j + 1 <= N + 1) { if(k - 1 >= 0 and dp2[i][j + 1][k - 1] + X[j + 1] - X[j] <= T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k - 1] + X[j + 1] - X[j]); } if(dp2[i][j + 1][k] + X[j + 1] - X[j] > T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k] + X[j + 1] - X[j]); } if(k - 1 >= 0 and dp1[i][j + 1][k - 1] + (L - X[j]) + X[i] <= T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k - 1] + (L - X[j]) + X[i]); } if(dp1[i][j + 1][k] + (L - X[j]) + X[i] > T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k] + (L - X[j]) + X[i]); } } if(dp1[i][j][k] != llINF or dp2[i][j][k] != llINF) { ans = k; } } } } 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...