제출 #174683

#제출 시각아이디문제언어결과실행 시간메모리
174683CaroLinda수열 (APIO14_sequence)C++14
49 / 100
183 ms131072 KiB
#include <bits/stdc++.h> #define debug printf #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define ff first #define ss second #define pb push_back #define mk make_pair #define ll long long #define sz size() #define pii pair<int,int> #define all(x) x.begin(),x.end() #define tiii tuple<int,int,int> #define mkt make_tuple const int MAXN = 1e5+10 , MAXK = 210 ; using namespace std ; int n , k ; int a[MAXN] ; ll sufSum[MAXN] ; ll dp[MAXN][MAXK] , myOpt[MAXN][MAXK] ; void calcDp(int l , int r , int optmin , int optmax, int am ) { if( r < l ) return ; int mid = (l+r)>>1 ; ll opt , val=0 , cur ; lp(i,max(optmin,mid),optmax+1) { cur = dp[i][am-1] + (sufSum[mid] - sufSum[i])*sufSum[i] ; if( cur > val ) val = cur, opt = i ; } dp[mid][am] = val ; myOpt[mid][am] = opt ; calcDp(l,mid-1, optmin, opt , am ) ; calcDp(mid+1, r, opt, optmax, am ) ; } int main() { scanf("%d%d", &n, &k) ; lp(i,1,n+1) scanf("%d", &a[i] ) ; for(int i = n ; i > 0 ; i-- ) sufSum[i] = sufSum[i+1] + a[i] ; lp(i,1,k+1) calcDp(1,n - i,1,n-i+1,i) ; printf("%lld\n", dp[1][k] ) ; vector<int> ans ; int cur = 1 ; for(int i = k ; i > 0 ; i-- ) { cur = myOpt[cur][i] ; ans.pb(cur-1) ; } sort(all(ans)) ; for(int i : ans ) printf("%d " , i ) ; printf("\n") ; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k) ;
  ~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:50:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  lp(i,1,n+1) scanf("%d", &a[i] ) ;
              ~~~~~^~~~~~~~~~~~~~
sequence.cpp: In function 'void calcDp(int, int, int, int, int)':
sequence.cpp:42:8: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
  calcDp(l,mid-1, optmin, opt , am ) ;
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...