Submission #62618

#TimeUsernameProblemLanguageResultExecution timeMemory
62618VahanSplit the sequence (APIO14_sequence)C++17
50 / 100
2071 ms5020 KiB
#include<iostream> using namespace std; long long d[100007][201],n,k,a[200000],ss; int main() { cin>>n>>k; for(int i=1;i<=n;i++) { cin>>a[i]; ss+=a[i]; } long long s=0; for(int i=1;i<=n;i++) { s+=a[i]; for(int j=0;j<=min(i-1,200);j++) { if(j==0) { d[i][j]=s*s; continue; } long long e=0; for(int z=i;z>=j+1;z--) { e+=a[z]; if(d[i][j]==0) d[i][j]=e*e+d[z-1][j-1]; d[i][j]=min(d[i][j],e*e+d[z-1][j-1]); } } } cout<<(ss*ss-d[n][k])/2<<endl; int l=n,r=k; s=0; for(int i=n;i>=2;i--) { s+=a[i]; if(s*s+d[i-1][r-1]==d[l][r]) { cout<<i-1<<" "; s=0; r--; if(r==0) break; l=i-1; } } return 0; } /* 7 3 4 1 3 4 0 2 3*/
#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...