제출 #174684

#제출 시각아이디문제언어결과실행 시간메모리
174684CaroLinda수열 (APIO14_sequence)C++14
49 / 100
2070 ms85752 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] ; int myOpt[MAXN][MAXK] ; ll sufSum[MAXN] ; ll dp[MAXN][2] ; 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%2)] + (sufSum[mid] - sufSum[i])*sufSum[i] ; if( cur > val ) val = cur, opt = i ; } dp[mid][am%2] = 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%2] ) ; int cur = 1 ; for(int i = k ; i > 0 ; i-- ) { cur= myOpt[cur][i] ; printf("%d " , cur-1 ) ; } printf("\n") ; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:50: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:51: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:41:17: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
  myOpt[mid][am] = opt ;
  ~~~~~~~~~~~~~~~^~~~~
#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...