Submission #1066284

#TimeUsernameProblemLanguageResultExecution timeMemory
1066284beaconmcSplit the sequence (APIO14_sequence)C++14
28 / 100
863 ms16476 KiB
#include <vector> #include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; ll dp[1001][201]; vector<ll> prevs[1001][201]; int main(){ deque<vector<ll>> sus; ll n,k; cin >> n >> k; vector<ll> arr(n); vector<ll> pref(n); FOR(i,0,n) cin >> arr[i]; pref[0] = arr[0]; FOR(i,1,n) pref[i] = pref[i-1]+arr[i]; FOR(i,0,1001)FOR(j,0,201) dp[i][j] = 0; FOR(i,1,n+1){ FOR(j,1,k+1){ FOR(m,0, i){ ll temp = dp[m][j-1] + (pref[n-1] - pref[i-1]) * (pref[i-1]-pref[m]+arr[m]); if (dp[i][j] < temp){ dp[i][j] = temp; prevs[i][j] = {m, j-1}; } } if (dp[i-1][j] > dp[i][j]){ dp[i][j] = dp[i-1][j]; prevs[i][j] = {i-1, j}; } } } cout << dp[n][k] << endl; while (k != 0 || prevs[n][k].size()!=0){ vector<ll> sus = prevs[n][k]; if (k != sus[1]) cout << n << " "; n = sus[0]; k = sus[1]; } }
#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...