제출 #100230

#제출 시각아이디문제언어결과실행 시간메모리
100230TadijaSebez수열 (APIO14_sequence)C++11
100 / 100
1443 ms82040 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=100050; const int K=205; const ll inf=1e18; int a[N]; ll sum[N]; ll dp[N][2]; int best[K][N]; void Solve(int k, int ss, int se, int l, int r) { if(ss>se) return; int mid=ss+se>>1; dp[mid][k&1]=-inf; for(int i=l;i<=min(r,mid);i++) { ll tmp=dp[i-1][(k&1)^1]+(sum[mid]-sum[i-1])*sum[i-1]; if(tmp>dp[mid][k&1]) dp[mid][k&1]=tmp,best[k][mid]=i; } Solve(k,ss,mid-1,l,best[k][mid]); Solve(k,mid+1,se,best[k][mid],r); } int main() { int n,k; scanf("%i %i",&n,&k);k++; for(int i=1;i<=n;i++) scanf("%i",&a[i]),sum[i]=sum[i-1]+a[i],dp[i][0]=-inf; for(int i=1;i<=k;i++) Solve(i,i,n,i,n); printf("%lld\n",dp[n][k&1]); vector<int> ans; for(int i=n,j=k;i>0;i=best[j][i]-1,j--) ans.push_back(i); reverse(ans.begin(),ans.end()); ans.pop_back(); for(int i:ans) printf("%i ",i); return 0; }

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

sequence.cpp: In function 'void Solve(int, int, int, int, int)':
sequence.cpp:14:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
sequence.cpp: In function 'int main()':
sequence.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&k);k++;
  ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:28:62: 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("%i",&a[i]),sum[i]=sum[i-1]+a[i],dp[i][0]=-inf;
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#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...