Submission #68925

#TimeUsernameProblemLanguageResultExecution timeMemory
68925istleminHomecoming (BOI18_homecoming)C++14
62 / 100
1060 ms184524 KiB
#include<bits/stdc++.h> #include "homecoming.h" using namespace std; #define rep(i,a,b) for(int i = a; i<int(b);++i) #define all(v) v.begin(),v.end() #define sz(v) v.size() #define trav(a,c) for(auto a: c) typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> pii; ll n,k; vi a,b; vi sumB; ll start; ll getSum(ll l,ll r){ if(r<l) return 0; return sumB[r]-sumB[l]; } ll getCost(ll l,ll r){ if(l>=n) return getCost(l-n,r-n); if(r>n) return getCost(l,n)+getCost(0,r-n); if(l<start) return getSum(start,r); return getSum(l,r); } long long solve(int N, int K, int *A, int *B){ n = N; k = K; a.resize(n); b.resize(n); rep(i,0,n) a[i] = A[i]; rep(i,0,n) b[i] = B[i]; sumB.resize(n+1); rep(i,1,n+1) sumB[i] = sumB[i-1]+b[i-1]; ll best = 0; rep(_start,0,k+1){ start = _start; ll curr = -getSum(0,start); vi dpFilled(n+k+1); vi dpEmpty(n+k+1); for(int i = n-1;i>=0;i--){ ll cost = getCost(i+k-1,i+k); dpFilled[i] = max(dpFilled[i],a[i]-cost+dpFilled[i+1]); dpFilled[i] = max(dpFilled[i],dpEmpty[i+k]); cost = getCost(i,i+k); dpEmpty[i] = max(dpEmpty[i],a[i]-cost+dpFilled[i+1]); dpEmpty[i] = max(dpEmpty[i],dpEmpty[i+1]); } curr += dpEmpty[0]; //cout<<start<<": "<<curr<<endl; best = max(best,curr); } return best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...