Submission #569539

# Submission time Handle Problem Language Result Execution time Memory
569539 2022-05-27T13:30:13 Z SAAD Split the sequence (APIO14_sequence) C++17
0 / 100
61 ms 131072 KB
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
ll x[100005] , c[100005] ;
pair<ll, ll> dp[100002][202];
int n;
pair<ll,ll> calc ( int idx , int k ) {
    if (dp[idx][k].F != -1) return dp[idx][k];
    if (k == 0) return dp[idx][k] = { 0,-1 };
    for (int i = n-k; i >= idx; i--) {
        ll resi = calc(i + 1, k - 1).F;
        ll a = (c[n]-c[i]) * (c[i]-c[idx-1]);
        //cout << idx << ":" << i << " " << k << " " << a << endl ;
        resi += a;
        if (dp[idx][k].first < resi) {
            dp[idx][k] = { resi, i+1 };
        }
    }
    return dp[idx][k];
}
int main()
{
    int k;
    cin >> n >> k;
    memset(dp,-1,sizeof(dp));
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
        c[i] += c[i - 1] + x[i];
    }
    cout << calc(1, k).F << endl ;
    vi res;
    int a = dp[1][k].S;
    while ( k > 0 ) {
    	res.push_back(a);
        k--;
        a = dp[a][k].S;
        
    }
    for (auto i : res) cout << i-1 << " ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 55 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 61 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 58 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -