제출 #770758

#제출 시각아이디문제언어결과실행 시간메모리
770758OrazB수열 (APIO14_sequence)C++14
50 / 100
2084 ms48712 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 = 10005; int n, k, par[N][202]; ll pref[N], dp[N][202]; 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++){ 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; par[i][x] = j; } } } } cout << dp[n][k] << '\n'; int cur = 0; while(1){ n = par[n][k-cur++]; if(!n)break; cout << n << ' '; } }
#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...