# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
744972 | zeta7532 | Split the sequence (APIO14_sequence) | C++17 | 2088 ms | 48212 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 target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
int main() {
ll N,K;
cin >> N >> K;
K++;
vector<ll> A(N);
rep(i,N) cin >> A[i];
vector<ll> sum(N+1);
sum[0]=0;
rep(i,N) sum[i+1]=sum[i]+A[i];
vector<vector<ll>> dp(N+1,vector<ll>(K+1,0));
ll ans[N+1][K+1][2];
rep(i,N){
rep(k,min(i+1,K)){
dp[i+1][k+1]=-1;
for(ll j=k;j<i+1;j++){
ll x=dp[j][k]+(sum[i+1]-sum[j])*(sum[N]-sum[i+1]);
if(dp[i+1][k+1]<x){
dp[i+1][k+1]=x;
ans[i+1][k+1][0]=j;
ans[i+1][k+1][1]=k;
}
}
}
}
cout << dp[N][K] << endl;
ll y=N,z=K;
vector<ll> ANS;
while(1){
ll ny=ans[y][z][0];
ll nz=ans[y][z][1];
y=ny;
z=nz;
if(y==0) break;
ANS.push_back(y);
}
reverse(all(ANS));
rep(i,ANS.size()) cout << ANS[i] << " ";
cout << endl;
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... |