제출 #1132331

#제출 시각아이디문제언어결과실행 시간메모리
1132331antonnCollecting Stamps 3 (JOI20_ho_t3)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> #define F first #define S second using namespace std; using ll = long long; using pi = pair<int, int>; using vi = vector<int>; template<class T> bool ckmin(T& a, T b) { return b < a ? a = b, true : false; } template<class T> bool ckmax(T& a, T b) { return a < b ? a = b, true : false; } const int N = 2e2+7; int n, L, x[N], t[N]; ll dp[N][N][N][2]; bool can(int a, ll t, int b, ll te, bool around = 0) { int d = (around == 0 ? abs(a - b) : L - abs(a - b)); return te + d <= t; } int main() { ios::sync_with_stdio(0); cin.tie(0); 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 cnt = 0; cnt <= n; ++cnt) { dp[i][j][cnt][0] = 1e18; dp[i][j][cnt][1] = 1e18; } } } dp[0][0][0][0] = dp[0][0][0][1] = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; i + j <= n; ++j) { for (int cnt = 0; cnt <= i + j; ++cnt) { ckmin(dp[i+1][j][cnt][0], dp[i][j][cnt][0]+x[i+1]-x[i]); ckmin(dp[i][j+1][cnt][1], dp[i][j][cnt][1]+x[n-j+1]-x[n-j]); if (can(x[i+1], t[i+1], x[i], dp[i][j][cnt][0], 0)) ckmin(dp[i+1][j][cnt+1][0], dp[i][j][cnt][0]+x[i+1]-x[i]); if (can(x[i+1], t[i+1], x[n-j+1], dp[i][j][cnt][1], 1)) ckmin(dp[i+1][j][cnt+1][0], dp[i][j][cnt][1]+x[i+1]+L-x[n-j+1]); if (can(x[n-j], t[n-j], x[n-j+1], dp[i][j][cnt][1], 0)) ckmin(dp[i][j+1][cnt+1][1], dp[i][j][cnt][1]+x[n-j+1]-x[n-j]); if (can(x[n-j], t[n-j], x[i], dp[i][j][cnt][0], 1)) ckmin(dp[i][j+1][cnt+1][1], dp[i][j][cnt][0]+x[i]+L-x[n-j]); } } } int ans = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { for (int cnt = 0; cnt <= n; ++cnt) { if (dp[i][j][cnt][0] != 1e18) ckmax(ans, cnt); if (dp[i][j][cnt][1] != 1e18) ckmax(ans, cnt); } } } 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...