제출 #174686

#제출 시각아이디문제언어결과실행 시간메모리
174686CaroLinda수열 (APIO14_sequence)C++14
60 / 100
2025 ms85480 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 , opt = mid ; ll val=0 , cur ; lp(i,max(optmin-1,mid)+1,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] ) ;
              ~~~~~^~~~~~~~~~~~~~
#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...