Submission #7641

# Submission time Handle Problem Language Result Execution time Memory
7641 2014-08-13T10:09:30 Z imsifile Split the sequence (APIO14_sequence) C++
0 / 100
0 ms 83200 KB
#include<stdio.h>
#define sq(a) ((a)*(a))

typedef long long lld;

int n, k, di[100100][202];
lld ba[100100], dy[100100][2], sum[100100];

int main(){
	int i, i2, j, t=1;
	scanf("%d%d", &n, &k);
	for(i=1; i<=n; i++)scanf("%d", &ba[i]), sum[i]=sum[i-1]+ba[i];
	for(i=1; i<=n; i++)dy[i][0]=sq(sum[i]);
	for(j=1; j<=k; j++){
		for(i=j+1, i2=j; i<=n; i++){
			for(; i2<i-1; i2++){
				if(sum[i2]>(lld)j*(sum[i]-sum[i2]))break;
			}
			di[i][j]=i2, dy[i][t]=dy[i2][1-t]+sq(sum[i]-sum[i2]);
			if(i2>j){
				if(dy[i][t]>dy[i2-1][1-t]+sq(sum[i]-sum[i2-1])){
					di[i][j]=i2-1, dy[i][t]=dy[i2-1][1-t]+sq(sum[i]-sum[i2-1]);
				}
			}
		}
		t=1-t;
	}
	printf("%lld\n", (sq(sum[n])-dy[n][1-t])/2);
	for(i=n, j=k; j>0; j--)printf("%d ", di[i][j]), i=di[i][j];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 83200 KB Output is correct - contestant found the optimal answer: 108 == 108
2 Correct 0 ms 83200 KB Output is correct - contestant found the optimal answer: 999 == 999
3 Correct 0 ms 83200 KB Output is correct - contestant found the optimal answer: 0 == 0
4 Incorrect 0 ms 83200 KB Output isn't correct - contestant didn't find the optimal answer: 1542521 < 1542524
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -