Submission #73938

#TimeUsernameProblemLanguageResultExecution timeMemory
73938jiaqing23Homecoming (BOI18_homecoming)C++14
100 / 100
267 ms185688 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; typedef set<ll>::iterator sit; typedef map<ll,ll>::iterator mit; typedef pair<int,pair<int,int> > tri; ll dp[2000050][2]; ll sum[4000050]; long long solve(int N, int K, int *A, int *B){ ll ans = 0; //din pass first subject dp[0][0] = 0; dp[0][1] = -(ll)1e18; sum[0] = B[0]; for(int i = 1; i < N; i++) sum[i] = sum[i-1] + (ll)B[i]; for(int i = N; i < 2 * N; i++) sum[i] = sum[N-1] + sum[i-N]; for(int i = 1; i < N; i++){ dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = (ll)A[i] + max(dp[i-1][0] - (sum[i+K-1]-sum[i-1]), dp[i-1][1] - (ll)B[(i+K-1)%N]); } ans = max(ans, max(dp[N-1][0], dp[N-1][1])); //pass the first subject dp[0][1] = (ll)A[0] - sum[K-1]; dp[0][0] = -(ll)1e18; for(int i = 0; i < K; i++) B[i] = 0; sum[0] = B[0]; for(int i = 1; i < N; i++) sum[i] = sum[i-1] + (ll)B[i]; for(int i = N; i < 2 * N; i++) sum[i] = sum[N-1] + sum[i-N]; for(int i = 1; i < N ; i++){ dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = (ll)A[i] + max(dp[i-1][0] - (sum[i+K-1]-sum[i-1]), dp[i-1][1] - (ll)B[(i+K-1)%N]); //cout<<i<<' '<<dp[i][0]<<' '<<dp[i][1] <<endl; } ans = max(ans, max(dp[N-1][0], dp[N-1][1])); return 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...