이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//noey power
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
const ll inf = 1e16;
int n,m;
int a[maxn];
ll sum[maxn];
ll dp[maxn], noey[maxn];
int rec[maxn][205];
void solve(int k, int l, int r, int bl, int br) {
if(l>r) return ;
int x = (l+r)/2;
for(int y=bl;y<=min(x-1,br);y++) {
ll t = dp[y] + sum[y]*sum[x] - sum[y]*sum[y];
if(t > noey[x]) {
noey[x] = t;
rec[x][k] = y;
}
}
solve(k,l,x-1,bl,rec[x][k]); solve(k,x+1,r,rec[x][k],br);
}
void go(int x, int k) {
if(x==0) return ;
go(rec[x][k], k-1);
if(x!=n) printf("%d ",x);
}
int main() {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) sum[i] = sum[i-1] + a[i];
for(int x=1;x<=n;x++) dp[x] = -inf;
for(int k=1;k<=m+1;k++) {
for(int x=0;x<=n;x++) noey[x] = -inf;
solve(k,1,n,0,n-1);
for(int x=0;x<=n;x++) dp[x] = noey[x];
}
printf("%lld\n",dp[n]);
go(n,m+1);
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
sequence.cpp:31:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%d",&a[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... |