제출 #409800

#제출 시각아이디문제언어결과실행 시간메모리
409800nicholask수열 (APIO14_sequence)C++14
39 / 100
2067 ms31900 KiB
#include <bits/stdc++.h> #define int long long #define x first #define y second #define pb push_back using namespace std; signed main(){ int n,k; cin>>n>>k; int a[n+1]; for (int i=1; i<=n; i++) cin>>a[i]; int ps[n+1]; for (int i=0; i<=n; i++){ if (!i) ps[i]=0; else ps[i]=ps[i-1]+a[i]; } pair <int,int> dp[n+1][k+1]; for (int i=0; i<=n; i++){ for (int j=0; j<=k; j++) dp[i][j]={-1e18,i}; } for (int i=1; i<=n-1; i++) dp[i][1]={ps[i]*(ps[n]-ps[i]),i}; for (int j=2; j<=k; j++){ for (int i=1; i<=n; i++){ for (int l=1; l<i; l++){ pair <int,int> tp={dp[l][j-1].x+(ps[i]-ps[l])*(ps[n]-ps[i]),l}; dp[i][j]=max(dp[i][j],tp); } } } int ma=0,wh; for (int i=1; i<=n; i++){ if (dp[i][k].x>ma){ ma=dp[i][k].x; wh=i; } } cout<<ma<<endl; vector <int> ans; ans.pb(wh); int la=k; for (int i=k; i>1; i--){ wh=dp[wh][i].y; ans.pb(wh); } reverse(ans.begin(),ans.end()); for (auto&i:ans) cout<<i<<' '; }

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

sequence.cpp: In function 'int main()':
sequence.cpp:40:6: warning: unused variable 'la' [-Wunused-variable]
   40 |  int la=k;
      |      ^~
#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...