이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <algorithm>
#define M 100009
using namespace std;
int n, k,path[200][M];
long long int d[209][M],ans,s[M];
long long int f(int i, int j, int r){
return d[i][r] + (s[n] - s[j])*(s[j] - s[r]);
}
int main(){
int i, j;
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &s[i]);
for (i = 1; i <= n; i++) s[i] = s[i - 1] + s[i];
int pivot;
for (i = 1; i <= k; i++){
pivot = 0;
for (j = 1; j <= n; j++){
while (s[j] >= (s[n] + s[pivot]) / 2 && f(i - 1, j, pivot) <= f(i - 1, j, pivot + 1) && pivot < j) pivot++;
d[i][j] = f(i - 1, j, pivot);
path[i][j] = pivot;
}
}
for (i = 1; i <= n; i++) ans = max(ans, d[k][i]);
for (i = 1; i <= n; i++){
if (ans == d[k][i]){
int temp = i;
for (j = k; j >= 1; j--){
s[j] = temp;
temp = path[j][temp];
}
break;
}
}
for (j = 1; j <= k; j++) printf("%d ", s[j]);
printf("\n%d", ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |