Submission #577688

#TimeUsernameProblemLanguageResultExecution timeMemory
577688JomnoiCollecting Stamps 3 (JOI20_ho_t3)C++17
0 / 100
1 ms724 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] = L; for(int k = 0; k < N; k++) { for(int i = 0; i <= N; i++) { for(int j = 0; j <= N; j++) { dp1[i][j][k] = llINF; dp2[i][j][k] = llINF; } } } int ans = 0; dp1[0][N][0] = dp2[0][N][0] = 1; for(int k = 0; k < N; k++) { for(int i = 0; i <= N; i++) { for(int j = N; j >= 0; j--) { long long dist; if(i - 1 >= 0) { dist = X[i] - X[i - 1]; if(k - 1 >= 0 and dp1[i - 1][j][k - 1] + dist <= T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k - 1] + dist); } if(dp1[i - 1][j][k] + dist > T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k] + dist); } dist = (L - X[j]) + X[i]; if(k - 1 >= 0 and dp2[i - 1][j][k - 1] + dist <= T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k - 1] + dist); } if(dp2[i - 1][j][k] + dist > T[i]) { dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k] + dist); } } if(j + 1 <= N) { dist = X[j + 1] - X[j]; if(k - 1 >= 0 and dp2[i][j + 1][k - 1] + dist <= T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k - 1] + dist); } if(dp2[i][j + 1][k] + dist > T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k] + dist); } dist = (L - X[j]) + X[i]; if(k - 1 >= 0 and dp1[i][j + 1][k - 1] + dist <= T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k - 1] + dist); } if(dp1[i][j + 1][k] + dist > T[j]) { dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k] + dist); } } 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...