Submission #8141

#TimeUsernameProblemLanguageResultExecution timeMemory
8141gs13031Split the sequence (APIO14_sequence)C++98
0 / 100
0 ms84688 KiB
#include<stdio.h> int n, k, d[100010], dd[100010], a[100010], s[100010], sl[100010][210], j; void get_l(int st, int ed, int left, int right) { int i, m=2147483647, x, q, p; if(left>right) return; p=(left+right)/2; if(st==ed) { for(i=left; i<=p; ++i) sl[i][j]=st; return; } for(i=st; i<=ed; ++i) { x=d[i]+(s[p]-s[i])*(s[p]-s[i]); if(m>x){ m=x; q=i; } } sl[p][j]=q; get_l(st, q, left, p-1); get_l(q, ed, p+1, right); return; } void back(int x, int dep) { if(dep>1) back(sl[x][dep], dep-1); printf("%d ", sl[x][dep]+1); return; } int main() { int i, l; scanf("%d%d", &n, &k); for(i=1; i<=n; ++i) scanf("%d", &a[i]); for(i=1; i<=n; ++i) s[i]=s[i-1]+a[i]; for(i=1; i<=n; ++i) d[i]=s[i]*s[i]; for(j=2; j<=k+1; ++j) { //l을 찾는다 get_l(j-1, n, j, n); for(i=j; i<=n; ++i) { l=sl[i][j]; dd[i]=d[l]+(s[i]-s[l])*(s[i]-s[l]); } for(i=j; i<=n; ++i) d[i]=dd[i]; } printf("%d\n", (s[n]*s[n]-d[n])/2); back(n, k); }
#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...