| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 869313 | prohacker | Split the sequence (APIO14_sequence) | C++14 | 126 ms | 5612 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 1010;
const int INF = INT_MAX;
const int mod = 1e9+7;
int n,m;
ll dp[N][210],ans;
int s[N],trace[N][210];
stack<int> st;
int get(int l, int r) {
    return s[r] - s[l-1];
}
signed main()
{
    if (fopen("sequence.inp", "r")) {
        freopen("sequence.inp", "r", stdin);
        freopen("sequence.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1 ; i <= n ; i++) {
        int x; cin >> x;
        s[i] = s[i-1] + x;
    }
    s[n+1] = s[n];
    for(int k = 1 ; k <= m+1 ; k++) {
        for(int i = 1 ; i <= n+1 ; i++) {
            for(int j = 0 ; j < i ; j++) {
                if(dp[j][k-1]+1LL*(s[i]-s[j])*(s[n]-s[i]) > dp[i][k]) {
                    dp[i][k] = dp[j][k-1]+1LL*(s[i]-s[j])*(s[n]-s[i]);
                    trace[i][k] = j;
                }
            }
        }
    }
    cout << dp[n][m+1] << '\n';
    while(m+1 > 1) {
        n = trace[n][m+1];
        st.push(n);
        m--;
    }
    while(!st.empty()) {
        cout << st.top() << " ";
        st.pop();
    }
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
