제출 #304420

#제출 시각아이디문제언어결과실행 시간메모리
304420vipghn2003수열 (APIO14_sequence)C++14
100 / 100
1473 ms81848 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; const int N=1e5+5; const int K=205; int n,k,a[N],opt[K][N]; ll s[N],dp[2][N]; void calc(int lev,int l,int r,int L,int R) { if(l>r) return ; int mid=(l+r)/2; dp[1][mid]=1e18; for(int i=L;i<=min(mid-1,R);i++) { if(dp[1][mid]>dp[0][i]+(s[mid]-s[i])*(s[mid]-s[i])) { dp[1][mid]=dp[0][i]+(s[mid]-s[i])*(s[mid]-s[i]); opt[lev][mid]=i; } } calc(lev,l,mid-1,L,opt[lev][mid]); calc(lev,mid+1,r,opt[lev][mid],R); } main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>k; k++; for(int i=1;i<=n;i++) { cin>>a[i]; s[i]=s[i-1]+a[i]; } ll res=s[n]*s[n]; dp[0][0]=1e18; dp[1][0]=1e18; for(int i=1;i<=n;i++) { dp[0][i]=s[i]*s[i]; opt[1][i]=i; } for(int lev=2;lev<=k;lev++) { calc(lev,1,n,0,n-1); for(int j=0;j<=n;j++) dp[0][j]=dp[1][j]; } res-=dp[0][n]; cout<<res/2<<'\n'; int cur=n; while(k>1) { cur=opt[k][cur]; k--; cout<<cur<<' '; } } /* 7 3 4 1 3 4 0 2 3 */

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:27:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main()
      |      ^
#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...