제출 #62617

#제출 시각아이디문제언어결과실행 시간메모리
62617Vahan수열 (APIO14_sequence)C++17
33 / 100
43 ms4988 KiB
#include<iostream> using namespace std; long long d[201][100007],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...