Submission #612551

#TimeUsernameProblemLanguageResultExecution timeMemory
612551amunduzbaevHomecoming (BOI18_homecoming)C++17
100 / 100
155 ms78584 KiB
#ifndef EVAL #include "homecoming.h" #endif #include "bits/stdc++.h" using namespace std; typedef long long ll; const int N = 2e6 + 5; ll dp[N][2], pa[N], pb[N]; ll solve(int n, int k, int a[], int b[]){ for(int i=0;i<n;i++){ pa[i] = a[i]; if(i) pa[i] += pa[i-1]; pb[i] = b[i]; if(i) pb[i] += pb[i-1]; } for(int i=0;i<n;i++) memset(dp[i], 254, sizeof dp[i]); dp[0][1] = a[0] - pb[k - 1]; for(int i=1;i<n;i++){ dp[i][0] = max(dp[i-1][1], dp[i-1][0]); dp[i][1] = max(dp[i-1][1] + a[i] - (i + k - 1 < n ? b[i + k - 1] : 0), dp[i-1][0] + a[i] - (pb[min(i + k - 1, n - 1)] - pb[i - 1])); } ll res = max(dp[n - 1][0], dp[n - 1][1]); for(int i=0;i<n;i++) memset(dp[i], 254, sizeof dp[i]); dp[0][0] = 0; for(int i=1;i<n;i++){ dp[i][0] = max(dp[i-1][1], dp[i-1][0]); dp[i][1] = max(dp[i-1][1] + a[i] - b[(i + k - 1) % n], dp[i-1][0] + a[i] - (pb[min(i + k - 1, n - 1)] - pb[i - 1] + (i + k > n ? pb[i + k - 1 - n] : 0))); } res = max({res, dp[n - 1][0], dp[n - 1][1]}); return res; } /* 1 3 2 40 80 100 140 0 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...