제출 #770754

#제출 시각아이디문제언어결과실행 시간메모리
770754OrazB수열 (APIO14_sequence)C++17
33 / 100
145 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define ll long long int #define pb push_back const int N = 1001; int n, k; ll pref[N], dp[N][201]; vector<int> E[N][201]; int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++){ int x; cin >> x; pref[i] = pref[i-1]+x; } for (int i = 2; i <= n; i++){ for (int x = 1; x <= k; x++){ int pos = 0; for (int j = 1; j < i; j++){ ll cur = dp[j][x-1]+(pref[i]-pref[j])*pref[j]; if (dp[i][x] <= cur){ dp[i][x] = cur; pos = j; } } E[i][x].insert(E[i][x].end(), all(E[pos][x-1])); E[i][x].pb(pos); } } cout << dp[n][k] << '\n'; for (auto i : E[n][k]) cout << 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...