이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int v[100005],opt[205][100005];
ll sum[100005],dp[2][100005];
vector<int>ans;
void calc(int st,int dr,int st2,int dr2,int nr,int ind)
{
if (st>dr)
return ;
int mij=(st+dr)/2;
ll val=-1;
int poz=1,i;
for(i=st2;i<=min(mij-1,dr2);i++){
ll cur=dp[nr^1][i]+(sum[mij]-sum[i])*sum[i];
if (cur>val)
val=cur,poz=i;
}
opt[ind][mij]=poz;
dp[nr][mij]=val;
calc(st,mij-1,st2,poz,nr,ind);
calc(mij+1,dr,poz,dr2,nr,ind);
}
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,k,i;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
scanf("%d",&v[i]),sum[i]=sum[i-1]+v[i];
for(i=1;i<=k;i++)
calc(1,n,1,n,i%2,i);
printf("%lld\n",dp[k%2][n]);
int cur=n;
for(i=k;i>=1;i--)
ans.push_back(opt[i][cur]),cur=opt[i][cur];
for(auto it=ans.rbegin();it!=ans.rend();it++)
printf("%d ",*it);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int main()':
sequence.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
29 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
sequence.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
31 | scanf("%d",&v[i]),sum[i]=sum[i-1]+v[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... |