제출 #37618

#제출 시각아이디문제언어결과실행 시간메모리
37618mr_banana수열 (APIO14_sequence)C++14
100 / 100
1229 ms83272 KiB
#include <bits/stdc++.h> using namespace std; const int MN=1e5+10; long long dp[2][MN]; int a[MN]; long long ps[MN]; int dp2[201][MN]; long long sq(int x){ return 1ll*x*x; } void solve(int d,int l,int r,int ol,int orr){ int d1=d%2; if(l>=r){ return ; } int mid=(l+r)/2; dp2[d][mid]=ol; dp[d1][mid]=0; for(int i=ol;i<orr && i<mid;i++){ long long tmp=dp[d1^1][i]+1ll*(ps[mid+1]-ps[i+1])*ps[i+1]; if(dp[d1][mid]<=tmp){ dp[d1][mid]=tmp; dp2[d][mid]=i; } } solve(d,l,mid,ol,dp2[d][mid]+1); solve(d,mid+1,r,dp2[d][mid],orr); } int main() { int n,k; scanf("%d %d",&n,&k); for(int i=0;i<n;i++){ scanf("%d",&a[i]); ps[i+1]=ps[i]+a[i]; } for(int i=1;i<=k;i++){ solve(i,0,n,0,n); } printf("%lld\n",dp[k%2][n-1]); int x=n-1; vector<int> ans; for(int i=k;i>0;i--){ ans.push_back(dp2[i][x]+1); x=dp2[i][x]; } for(int i=k-1;i>=0;i--){ printf("%d ",ans[i]); } }

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

sequence.cpp: In function 'int main()':
sequence.cpp:33:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
                         ^
sequence.cpp:35:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[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...