제출 #732568

#제출 시각아이디문제언어결과실행 시간메모리
732568ac2hu수열 (APIO14_sequence)C++14
39 / 100
2080 ms102264 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 1e5 + 10; const int K = 200 + 10; int n, k, a[N], dp[N][K], b[N][K]; signed main(){ iostream::sync_with_stdio(false);cin.tie(nullptr); cin >> n >> k; for(int i = 1;i<=n;i++)cin >> a[i]; for(int i = 1;i<=n;i++)a[i] += a[i - 1]; for(int l = 1;l<=k;l++){ for(int i = 1;i<=n;i++){ for(int j = i - 1;j>=1;j--){ int C = (a[i] - a[j])*a[j] + dp[j][l - 1]; if(C >= dp[i][l])dp[i][l] = C, b[i][l] = j; } } } cout << dp[n][k] << "\n"; vector<int> v = {n}; for(int l = k;l>=1;l--){ v.push_back(b[v.back()][l]); } reverse(v.begin(), v.end());v.pop_back();reverse(v.begin(), v.end()); for(int e : v)cout << e << " "; 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...