# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
855329 | vjudge1 | Split the sequence (APIO14_sequence) | C++17 | 3 ms | 604 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>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
using namespace std;
using lol= long long int;
typedef long long ll;
typedef long double ld;
typedef long long unsigned lli;
// #define _MAXM 16000
#define cl clear
// #define int ll
#define db double
#define pb push_back
#define ers erase
#define ds resize
#define W INT_MIN
#define mp make_pair
#define pll pair< long , long >
#define pii pair<ll, ll>
#define bc back()
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
#define doc (clock() * 1.0 / CLOCKS_PER_SEC) < 1.0
#define all(v) v.begin(),v.end()
const int MAX = 100 + 5;
const int LOG = 18;
const ll INF = 1e9 + 7;
const ll inf = 1e18;
const int maxn = 1e5+5;
const double me = 1e-9;
const double PI=acos(-1.0);
const int M= 1e6;
const int mod = 998244353;
const int mxn=2e5+3;
const int MAXA = 1e6 + 10;
const int MOD = 1e9 + 7;
const int DN = 4008;
const int N = 1e5 + 123;
int n, k;
void kick(){
cin >> n >> k;
vector< ll > a(n + 1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
vector< vector< ll > > dp(k + 2, vector< ll >(n + 2, -INF));
vector < vector< int > > p(k + 2, vector<int>(n + 2, 0));
dp[0][0] = 0;
vector< ll > pref(n + 2, 0);
for(int i = 1; i <= n; i++){
pref[i] += pref[i - 1];
pref[i] += a[i];
}
for(int i = 1; i <= k + 1; i++){
for(int j = 1; j <= n; j++){
for(int k = 0; k < j; k++){
if(dp[i][j] < dp[i - 1][k] + (pref[j] - pref[k]) * pref[k]){
dp[i][j] = dp[i - 1][k] + (pref[j] - pref[k]) * pref[k];
p[i][j] = k;
}
}
}
}
vector< int > ans;
int cur = n;
for(int i = k; i > 0; i--){
ans.push_back(p[i + 1][cur]);
cur = p[i + 1][cur];
}
cout << dp[k + 1][n] << '\n';
reverse(all(ans));
for(auto i: ans){
cout << i << " ";
}
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.in", "r" ,stdin);
freopen("output.in", "w", stdout);
#endif
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T = 1;
// cin >> T;
// cout.flush();
while(T--){
kick();
}
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... |