Submission #201585

#TimeUsernameProblemLanguageResultExecution timeMemory
201585theStaticMindCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
121 ms128300 KiB
#include<bits/stdc++.h> #define pb push_back #define ii pair<int,int> #define all(x) (x).begin(),(x).end() #define INF 100000000000000000 #define modulo 1000000007 #define mod 998244353 #define int long long int using namespace std; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("q.gir","r",stdin); // freopen("q.cik","w",stdout); int n, L, ans = 0; cin >> n >> L; vector<int> X(n + 1),T(n + 1); X[0] = 0; T[0] = 0; for(int i = 1; i <= n; i++)cin >> X[i]; for(int i = 1; i <= n; i++)cin >> T[i]; X.pb(L); T.pb(0); int dp[n + 1][n + 2][n + 1][2]; for(int i = 0; i <= n; i++){ for(int j = 0; j <= n + 1; j++){ for(int k = 0; k <= n; k++){ if(k == 0 && i == 0 && j == n + 1)dp[i][j][k][0] = dp[i][j][k][1] = 0; else dp[i][j][k][0] = dp[i][j][k][1] = INF; } } } for(int cw = 0; cw <= n; cw++){ for(int ccw = n + 1; ccw > cw; ccw--){ for(int cnt = 0; cnt <= n; cnt++){ int cwT1 = INF, cwT2 = INF, ccwT1 = INF, ccwT2 = INF, cwT, ccwT; if(cnt > 0){ if(cw != 0)cwT1 = dp[cw - 1][ccw][cnt - 1][1] + (X[cw] - X[cw - 1]); if(cw != 0)cwT2 = dp[cw - 1][ccw][cnt - 1][0] + (L - X[ccw] + X[cw]); if(ccw != n + 1)ccwT1 = dp[cw][ccw + 1][cnt - 1][1] + (X[cw] + L - X[ccw]); if(ccw != n + 1)ccwT2 = dp[cw][ccw + 1][cnt - 1][0] + (X[ccw + 1] - X[ccw]); cwT = min(cwT1, cwT2); ccwT = min(ccwT1, ccwT2); if(T[cw] >= cwT) dp[cw][ccw][cnt][1] = min(dp[cw][ccw][cnt][1], cwT); if(T[ccw] >= ccwT) dp[cw][ccw][cnt][0] = min(dp[cw][ccw][cnt][0], ccwT); } cwT1 = INF, cwT2 = INF, ccwT1 = INF, ccwT2 = INF; if(cw != 0)cwT1 = dp[cw - 1][ccw][cnt][1] + (X[cw] - X[cw - 1]); if(cw != 0)cwT2 = dp[cw - 1][ccw][cnt][0] + (L - X[ccw] + X[cw]); if(ccw != n + 1)ccwT1 = dp[cw][ccw + 1][cnt][1] + (X[cw] + L - X[ccw]); if(ccw != n + 1)ccwT2 = dp[cw][ccw + 1][cnt][0] + (X[ccw + 1] - X[ccw]); cwT = min(cwT1, cwT2); ccwT = min(ccwT1, ccwT2); dp[cw][ccw][cnt][1] = min(dp[cw][ccw][cnt][1], cwT); dp[cw][ccw][cnt][0] = min(dp[cw][ccw][cnt][0], ccwT); } } } for(int i = 0; i <= n; i++){ for(int j = n + 1; j > i; j--){ for(int k = 0; k <= n; k++){ for(int q = 0; q < 2; q++){ if(dp[i][j][k][q] < 1e15) ans = max(ans, k); } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...