제출 #873302

#제출 시각아이디문제언어결과실행 시간메모리
873302NintsiChkhaidze수열 (APIO14_sequence)C++17
50 / 100
2077 ms131072 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define f first #define int ll using namespace std; const int N = 1e5 + 3; int a[N],p[N],dp[N][203],lst[N][203]; void get(int r,int k){ if (r < 1) dp[r][k] = 0; if (k == 0) dp[r][k] = 0; if (dp[r][k] != -1) return; for (int i = 1; i < r; i++){ int s1 = p[i],s2 = p[r] - p[i]; int reward = s1*s2; get(i,k - 1); int cur = dp[i][k - 1] + reward; if (cur > dp[r][k]){ dp[r][k] = cur; lst[r][k] = i; } } } signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,k; cin>>n>>k; for (int i = 1; i <= n; i++){ cin >> a[i]; p[i] = p[i - 1] + a[i]; } for (int r = 0; r <= n + 1; r++) for (int kk = 0; kk <= k; kk++) dp[r][kk] = -1; get(n,k); cout<<dp[n][k]<<endl; vector <int> ans; int id = n; for (int i = k; i >= 1; i--){ id = lst[id][i]; ans.pb(id); } for (int i = k - 1; i >= 0; i--) cout<<ans[i]<<" "; } /* 7 3 4 1 3 4 0 2 3 */
#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...