제출 #73898

#제출 시각아이디문제언어결과실행 시간메모리
73898jiaqing23Homecoming (BOI18_homecoming)C++14
0 / 100
49 ms20180 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 ans = 0; ll sum[4000050]; void calcsum(int N, int *B){ 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]; } long long solve(int N, int K, int *A, int *B){ //din pass first subject dp[0][0] = 0; dp[0][1] = -(ll)1e17; calcsum(N, B); for(int i = 1; i < N; i++){ dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = A[i] + max(dp[i-1][0] - (sum[i+K-1]-sum[i-1]), dp[i-1][1] - B[(i+K-1)%N]); } ans = max(ans, max(dp[N-1][0], dp[N-1][1])); //pass the first subject dp[0][1] = A[0] - sum[K-1]; dp[0][0] = -(ll)1e17; for(int i = 0; i < K; i++) B[i] = 0; calcsum(N, B); for(int i = 1; i < N ; i++){ dp[i][0] = max(dp[i-1][0], dp[i-1][1]); dp[i][1] = A[i] + max(dp[i-1][0] - (sum[i+K-1]-sum[i-1]), dp[i-1][1] - 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])); /* cout<<dp[N-1][0]<<' '<<dp[N-1][1]<<endl; cout<<endl; for(int i = 0; i < 2*N; i++) cout<<sum[i]<<' '; cout<<endl;*/ 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...