제출 #312020

#제출 시각아이디문제언어결과실행 시간메모리
312020minhcool수열 (APIO14_sequence)C++17
50 / 100
2094 ms41132 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define ins insert #define er erase typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int oo = 1e18 + 7, mod = 1e9 + 7; const int N = 2e5 + 5, K = 205; int n, k, a[N], suff[N]; ii dp[N][K]; signed main(){ ios_base::sync_with_stdio(0); cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = n; i >= 1; i--) suff[i] = (suff[i + 1] + a[i]); for(int i = 1; i <= n; i++){ for(int j = 1; j <= min(i, k); j++){ for(int itr = i - 1; itr >= (j - 1); itr--) if(dp[i][j].fi < dp[itr][j - 1].fi + (suff[itr + 1] - suff[i + 1]) * suff[i + 1]) dp[i][j] = {dp[itr][j - 1].fi + (suff[itr + 1] - suff[i + 1]) * suff[i + 1], itr}; } } int ind = k; for(int i = k + 1; i <= n; i++){ if(dp[i][k].fi > dp[ind][k].fi) ind = i; } cout << dp[ind][k].fi << "\n"; vector<int> pos; pos.clear(); int tmp = k; while(tmp){ pos.pb(ind); ind = dp[ind][tmp].se; tmp--; } for(int i = pos.size() - 1; i >= 0; i--) cout << pos[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...