Submission #757885

#TimeUsernameProblemLanguageResultExecution timeMemory
757885jasminCollecting Stamps 3 (JOI20_ho_t3)C++14
0 / 100
75 ms145356 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N=210; int dp[N][N][N][2]; const int INF=1e15; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, tot; cin >> n >> tot; vector<int> x(n+2); x[0]=0; x[n+1]=tot; for(int i=1; i<=n; i++){ cin >> x[i]; } vector<int> t(n+2); t[0]=-1; t[n+1]=-1; for(int i=1; i<=n; i++){ cin >> t[i]; } //initialize for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ for(int k=0; k<N; k++){ for(int x=0; x<2; x++){ dp[i][j][k][x]=INF; } } } } dp[0][0][0][0]=0; dp[0][0][0][1]=0; for(int l=0; l<=n; l++){ for(int r=0; r<=n; r++){ if(l+r>n) continue; for(int c=0; c<=n; c++){ for(int loc=0; loc<2; loc++){ int cor; if(loc==0){ cor = x[n+1-l]; } else{ cor = x[r]; } //walk right int distright = 0; if(loc==0){ distright = (tot-cor) + x[r+1]; } else{ distright = x[r+1] - cor; } dp[l][r+1][c][1] = min(dp[l][r+1][c][1], dp[l][r][c][loc] + distright); dp[l][r+1][c][0] = min(dp[l][r+1][c][0], dp[l][r][c][loc] + 2*distright); if( dp[l][r][c][loc] + distright <= t[r+1] ){ dp[l][r+1][c+1][1] = min( dp[l][r+1][c+1][1], dp[l][r][c][loc] + distright ); dp[l][r+1][c+1][0] = min( dp[l][r+1][c+1][0], dp[l][r][c][loc] + 2*distright); } //walk left int distleft=0; if(loc==0){ distleft = cor - x[n+1 - (l+1)]; } else{ distleft = tot - x[n+1 - (l+1)] + cor; } dp[l+1][r][c][0] = min(dp[l+1][r][c][0], dp[l][r][c][loc] + distleft); dp[l+1][r][c][1] = min(dp[l+1][r][c][1], dp[l][r][c][loc] + 2*distleft); if( dp[l][r][c][loc] + distleft <= t[n+1-(l+1)]){ dp[l+1][r][c+1][0] = min(dp[l+1][r][c+1][0], dp[l][r][c][loc] + distleft); dp[l+1][r][c+1][1] = min(dp[l+1][r][c+1][1], dp[l][r][c][loc] + 2*distleft); } } } } } //finding the largest one int ans=0; for(int i=0; i<=n; i++){ for(int j=0; j<=n; j++){ for(int k=0; k<=n; k++){ //cout << i << " " << j << " " << k << ": " << dp[i][j][k][0] << ", " << dp[i][j][k][1] << "\n"; for(int x=0; x<2; x++){ if(dp[i][j][k][x] != INF){ ans = max(ans, k); } } } } } 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...