이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define MAX 101010
lld arr[MAX], dp[MAX], p[MAX], s[MAX], ans[MAX];
int path[MAX][202];
void f(lld ind, lld l, lld r, lld low, lld high){
if(l>r||low>high) return;
lld i, mid=(l+r)/2, mini=mid-1;
dp[mid]=0;
for(i=max(low, ind-1);i<=min(high, mid-1);i++){
if(dp[mid]<p[i]+s[i]*(s[mid]-s[i])){
dp[mid]=p[i]+s[i]*(s[mid]-s[i]);
mini=i;
}
}
path[mid][ind]=(int)mini;
f(ind, l, mid-1, low, mini);
f(ind, mid+1, r, mini, high);
}
int main(void){
lld N, K;
scanf("%lld %lld", &N, &K);
lld i;
for(i=1;i<=N;i++){
scanf("%lld", &arr[i]);
s[i]=arr[i]+s[i-1];
}
int j;
for(i=2;i<=K+1;i++){
f(i, 1, N, 1, N);
for(j=1;j<=N;j++){
p[j]=dp[j];
}
}
printf("%lld\n", dp[N]);
for(i=K+1;i>=2;i--){
ans[i]=(lld)path[N][i];
N=(lld)path[N][i];
}
for(i=2;i<=K+1;i++){
printf("%lld ", ans[i]);
}
printf("\n");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
23 | scanf("%lld %lld", &N, &K);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
# | 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... |