Submission #899963

#TimeUsernameProblemLanguageResultExecution timeMemory
899963ByeWorldSplit the sequence (APIO14_sequence)C++14
28 / 100
64 ms3756 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#define bupol __builtin_popcount
#define int long long 
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
const int MAXN = 1e3+20;
const int MAXK = 210;
const int LOG = 20;
const int MOD = 1e9+7;
const int SQRT = 520;
const int INF = 1e18;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;

int n, k;
int a[MAXN], pr[MAXN];
int dp[MAXN][MAXK], ba[MAXN][MAXK];

signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        cin >> a[i]; pr[i] = pr[i-1]+a[i];
    }
    for(int i=0; i<=n+1; i++)
        for(int j=1; j<=k+1; j++) ba[i][j] = -1;
            
    for(int i=2; i<=n; i++){
        for(int j=1; j<=i-1; j++){
            for(int m=1; m<=min(k, min(i-1, j)); m++){
                if(dp[j][m-1] + pr[j] * (pr[i]-pr[j]) > dp[i][m]){ // cek yg optimal potong dmn
                    dp[i][m] = dp[j][m-1] + pr[j] * (pr[i]-pr[j]); // cmn ngebuild sampe dp[i][i-1]
                    ba[i][m] = j;
                }
            }
        }
    }
    cout << dp[n][k] << '\n';
    vector <int> vec;
    int nw = n;
    for(int i=k; i>=1; i--){
        nw = ba[nw][i];
        cout << nw << ' ';
    } 
    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...