제출 #351265

#제출 시각아이디문제언어결과실행 시간메모리
351265denkendoemeer수열 (APIO14_sequence)C++14
100 / 100
1317 ms81888 KiB
#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 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...