제출 #40499

#제출 시각아이디문제언어결과실행 시간메모리
40499mohammad_kilani수열 (APIO14_sequence)C++14
22 / 100
30 ms24204 KiB
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define oo 1000000000
const double PI = acos(-1);
const int N = 10010 , K = 201;
int arr[N] , n , k , a , b , low , high , best[N][K]; 
long long dp[N][K] , sum[N] , cur1 , cur2 ;

int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
		sum[i+1] = sum[i] + arr[i];
	}
	for(int i=0;i<k;i++)
		dp[n-1][i] = -1e17;
	for(int i=n-2;i>=0;i--){
		for(int j=0;j<k;j++){
			low = i + 1, high = n - 1 , a = i + 1;
			dp[i][j] = dp[a][j+1] + (sum[a] - sum[i]) * (sum[n] - sum[a]);
			best[i][j] = i + 1;
			while(high >= low){
				if(high - low <= 75) break;
				a = (low + low + high) / 3;
				b = (low + high + high) / 3;
				cur1 = dp[a][j+1] + (sum[a] - sum[i]) * (sum[n] - sum[a]);
				cur2 = dp[b][j+1] + (sum[b] - sum[i]) * (sum[n] - sum[b]);
				if(cur1 >= cur2){
					if(cur1 >= dp[i][j])
						best[i][j] = a;
					dp[i][j] = max(dp[i][j],cur1);
					low = a + 1;
				}
				else{
					if(cur2 >= dp[i][j])
						best[i][j] = b;
					dp[i][j] = max(dp[i][j],cur2);
					high = b - 1;
				}
			}
			for(int l=low;l<=high;l++){
				cur1 = dp[l][j+1] + (sum[l] - sum[i]) * (sum[n] - sum[l]);
				if(cur1 >= dp[i][j]){
					dp[i][j] = cur1;
					best[i][j] = l;
				}
			}
		}
	}
	printf("%lld\n",dp[0][0]);
 	int idx = 0;
 	for(int i=0;i<k;i++){
 		if(i > 0) putchar(' ');
 		printf("%d",best[idx][i]);
 		idx = best[idx][i];
 	}
 	puts("");
 	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:11:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
                     ^
sequence.cpp:13:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&arr[i]);
                      ^
#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...