Submission #362234

#TimeUsernameProblemLanguageResultExecution timeMemory
362234knightron0Collecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
149 ms130720 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN =205; int n, m; int a[MAXN], b[MAXN]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif cin>>n>>m; for(int i= 1;i<=n;i++){ cin>>a[i]; } for(int i= 1;i<=n;i++){ cin>>b[i]; } int dp[n+3][n+3][n+3][2]; for(int i = 0;i<=n+1;i++){ for(int j= n+1;j>=0;j--){ for(int k = 0;k<=n+1;k++){ dp[i][j][k][0] = dp[i][j][k][1] = INF; } } } // i = ith index from right // j = jth index from left // k = number of taken stamps dp[0][n+1][0][0] = 0; dp[0][n+1][0][1] = 0; int ans = 0; for(int i = 0;i<n;i++){ for(int j= n+1;j>=1;j--){ if(j <= i+1) break; for(int k = 0;k<=n;k++){ for(int p= 0;p<2;p++){ if(p == 0){ int last; if(j == n+1) last = m; else last = a[j]; int dist1 = a[i+1] - a[i]; int dist2 = a[i+1] + m - last; int t1 = min(dp[i][j][k][0] + dist1, dp[i][j][k][1] + dist2); int newk = k; if(t1 <= b[i+1]) newk++; dp[i+1][j][newk][0] = min(dp[i+1][j][newk][0], t1); if(dp[i+1][j][newk][0] < INF){ ans = max(ans,newk); } } else { int last; if(j == n+1) last = m; else last = a[j]; int dist1 = last - a[j-1]; int dist2 = a[i] + m - a[j-1]; int t2 = min(dp[i][j][k][1] + dist1, dp[i][j][k][0] + dist2); int newk = k; if(t2 <= b[j-1]) newk++; dp[i][j-1][newk][1] = min(dp[i][j-1][newk][1], t2); if(dp[i][j-1][newk][1] < INF){ ans = max(ans, newk); } } } } } } cout<<ans<<endl; 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...