Submission #48606

#TimeUsernameProblemLanguageResultExecution timeMemory
48606faishol27Split the sequence (APIO14_sequence)C++14
0 / 100
125 ms2220 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pl; typedef pair<int, int> pi; #define fi first #define se second const int MAXN = 1e3+5; const int MAXK = 205; // f(x,y) = score // x = pemotongan ke-x // y = indeks pemotongan // // int N, K; int data[MAXN], pref[MAXN], suff[MAXN]; int dp[MAXK][MAXN], tambah[MAXK][MAXN], ans=0; stack<int>putus; void cariSkenario(int cnt, int str, int score){ if(cnt == 0) return; for(;str>0;str--){ if(dp[cnt][str] == score){ putus.push(str); cariSkenario(cnt-1, str, score-tambah[cnt][str]); break; } } } int main(){ memset(data, 0, MAXN); memset(pref, 0, MAXN); memset(suff, 0, MAXN); memset(dp, 0, sizeof dp); cin >> N >> K; for(int i=1;i<=N;i++){ cin >> data[i]; pref[i] = data[i]+pref[i-1]; } for(int i=N;i>0;i--){ suff[i] = suff[i+1]+data[i]; } for(int i=1; i<=K; i++){ for(int j=1;j<N;j++){ if(j < i) continue; for(int l=0;l<j;l++){ int tmp = dp[i-1][l]+(pref[j]-pref[l])*suff[j+1]; if(dp[i][j] < tmp){ dp[i][j] = tmp; tambah[i][j] = tmp-dp[i-1][l]; } } } } for(int i=1;i<N;i++) ans = max(ans, dp[K][i]); cariSkenario(K, N-1, ans); cout << ans << endl; cout << putus.top(); putus.pop(); while(!putus.empty()){ cout << " " << putus.top(); putus.pop(); } cout << endl; }
#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...