제출 #731364

#제출 시각아이디문제언어결과실행 시간메모리
731364Alihan_8수열 (APIO14_sequence)C++17
50 / 100
2060 ms67948 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define pb push_back #define ln '\n' #define int long long bool chmin(int &x, int y){ bool flag = false; if ( x > y ){ x = y; flag |= true; } return flag; } bool chmax(int &x, int y){ bool flag = false; if ( x < y ){ x = y; flag |= true; } return flag; } const int N = 1e4 + 1, inf = 1e15 + 1; int dp[N][202], par[N][202]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector <int> p(n), pref(n + 1); for ( auto &i: p ) cin >> i; for ( int i = 0; i < n; i++ ){ pref[i + 1] = pref[i] + p[i]; } for ( int i = 0; i < N; i++ ){ for ( int j = 0; j <= 200; j++ ){ dp[i][j] = -inf; } } dp[0][0] = 0; ++k; for ( int i = 1; i <= n; i++ ){ for ( int j = 1; j <= k; j++ ){ for ( int l = 0; l < i; l++ ){ int v = (pref[i] - pref[l]) * (pref[n] - pref[i]); if ( chmax(dp[i][j], dp[l][j - 1] + v) ){ par[i][j] = l; } } } } cout << dp[n][k] << ln; vector <int> res; int it = n; while ( k > 0 ){ it = par[it][k--]; if ( it ) res.pb(it); } reverse(all(res)); for ( auto i: res ){ cout << i << ' '; } cout << '\n'; } /* 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...