제출 #83146

#제출 시각아이디문제언어결과실행 시간메모리
83146MrTEKSplit the sequence (APIO14_sequence)C++14
50 / 100
367 ms2616 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> ii; const int N = 1e3 + 5; const int M = 205; int a[N],n,k; ll pre[N],dp[N][M]; ll get(int l,int r) { return pre[r] - pre[l - 1]; } ll f(int x,int rem) { auto &res = dp[x][rem]; if (res != -1) return res; if (x == n + 1 || rem == 0) return res = 0; for (int i = x + 1 ; i <= n ; i++) { auto temp = f(i,rem - 1); res = max(res,get(i,n) * get(x,i - 1) + temp); } return res; } void write(int x,int rem) { if (x == n + 1 || rem == 0) return ; for (int i = x + 1 ; i <= n ; i++) { auto temp = dp[i][rem - 1]; if (dp[x][rem] == get(i,n) * get(x,i - 1) + temp) { cout << i - 1 << " "; write(i,rem - 1); break; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; for (int i = 1 ; i <= n ; i++) { cin >> a[i]; pre[i] = pre[i - 1] + a[i]; } memset(dp,-1,sizeof dp); cout << f(1,k) << "\n"; write(1,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...