Submission #997489

# Submission time Handle Problem Language Result Execution time Memory
997489 2024-06-12T11:34:24 Z vjudge1 Split the sequence (APIO14_sequence) C++17
0 / 100
25 ms 131072 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll N = 1e5 + 100;
const ll K = 205;

ll n, k, a[N], dp[N][K], par[N][K], suff[N];

int main(){
    cin >> n >> k;
    k++;

    for (ll i = 1; i <= n; i ++)
        cin >> a[i];
    for (ll i = n; i > 0; i --)
        suff[i] = suff[i + 1] + a[i];

    for (ll i = n; i > 0; i --){
        for (ll p = 2; p <= k; p ++){
            if (i + p - 1 > n){
                dp[i][p] = -1e18;
                par[i][p] = i;
                continue;
            }
            dp[i][p] = -1;

            for (int j = par[i + 1][p]; j > i; j --){
                ll val = dp[j][p - 1] + (suff[i] - suff[j]) * suff[j];
                if (val > dp[i][p]){
                    dp[i][p] = val;
                    par[i][p] = j;
                }
                else break;
            }

            // cout << i << " " << p << " goes to " << par[i][p] << endl;
        }
    }

    cout << dp[1][k] << endl;

    ll cur_i = 1;
    ll cur_k = k;

    while (cur_k > 1){
        cout << par[cur_i][cur_k] - 1 << " ";
        cur_i = par[cur_i][cur_k];
        cur_k--;
    }
    cout << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6488 KB contestant didn't find the optimal answer: 101 < 108
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6488 KB contestant didn't find the optimal answer: 1091106 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB contestant found the optimal answer: 610590000 == 610590000
2 Incorrect 1 ms 6584 KB contestant didn't find the optimal answer: 273471 < 311760000
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 10588 KB contestant didn't find the optimal answer: 20168074 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 39260 KB contestant didn't find the optimal answer: 1794289524 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -