이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll lim=1e5+4;
const ll inf=1e18;
vector<ll> dp_new;
vector<ll> dp_old;
ll t[lim];
ll n,k;
ll cost(ll l,ll r)
{
return t[r]+1-t[l];
}
void solve(ll l,ll r,ll optl,ll optr)
{
if(l>r) return ;
ll med=(l+r)>>1;
pair<ll,ll> bst={inf,-1};
for(ll i=optl;i<=min(med,optr);++i)
bst=min(bst,{dp_old[i-1]+cost(i,med),i});
ll opt=bst.second;
dp_new[med]=bst.first;
solve(l,med-1,optl,opt);
solve(med+1,r,opt,optr);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>k;
dp_new.resize(n+2,0);
dp_old.resize(n+2,0);
for(ll i=1;i<=n;++i)
cin>>t[i];
for(ll i=1;i<=n;++i)
dp_old[i]=cost(1,i);
for(ll i=2;i<=k;++i)
solve(1,n,1,n),
swap(dp_old,dp_new);
cout<<dp_old[n]<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |