제출 #1027213

#제출 시각아이디문제언어결과실행 시간메모리
1027213Luvidi수열 (APIO14_sequence)C++17
100 / 100
1000 ms83036 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back const int maxn=1e5,maxk=201; ll dp[maxn+1][2],a[maxn+1],pre[maxn+1]; int bt[maxn+1][maxk+1],c; void dnc(int l,int r,int opl,int opr){ if(l>r)return; int m=(l+r)/2; pll best={-1e18,0}; for(int i=opl;i<=opr&&i<m;i++){ best=max(best,{dp[i][(c-1)%2]+pre[i]*(pre[m]-pre[i]),i}); } dp[m][c%2]=best.fs; bt[m][c]=best.sc; dnc(l,m-1,opl,best.sc); dnc(m+1,r,best.sc,opr); } void solve() { int n,k; cin>>n>>k; k++; pre[0]=0; for(int i=1;i<=n;i++){ cin>>a[i]; pre[i]=pre[i-1]+a[i]; } for(int i=1;i<=n;i++)dp[i][0]=-1e18; for(c=1;c<=k;c++){ dnc(1,n,0,n); } cout<<dp[n][k%2]<<'\n'; int x=n; vector<int> v; for(int i=k;i>1;i--){ x=bt[x][i]; v.pb(x); } reverse(v.begin(),v.end()); for(int i:v)cout<<i<<' '; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...