# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
394810 | juggernaut | Split the sequence (APIO14_sequence) | C++14 | 1475 ms | 131076 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>
//#include<bits/extc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
//using namespace __gnu_pbds;
typedef long long ll;
//template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class T>bool umax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
#ifdef IOI2021SG
#define printl(args...)printf(args)
#else
#define printl(args...)((void)0)
#endif
int n,k,a[12];
pair<int,int>path[12][12][12];
ll dp[12][12][12];
ll rec(int l,int r,int k){
if(k==1)return 0ll;
if(l>r)return 0ll;
ll &res=dp[l][r][k];
if(~res)return res;
ll sum=0,pref=0;
res=0;
for(int i=l;i<=r;i++)sum+=a[i];
for(int i=l;i<r;i++){
sum-=a[i];
pref+=a[i];
for(int j=1;j<k;j++)if(umax(res,sum*pref+rec(l,i,j)+rec(i+1,r,k-j))){
path[l][r][k]={i,j};
}
}
return res;
}
int main(){
memset(dp,-1,sizeof dp);
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
ll ans=rec(1,n,k+1);
printf("%lld\n",ans);
queue<array<int,3>>q;
q.push({1,n,k+1});
while(!q.empty()){
auto v=q.front();
q.pop();
if(v[2]==1)continue;
printf("%d ",path[v[0]][v[1]][v[2]].fr);
q.push({v[0],path[v[0]][v[1]][v[2]].fr,path[v[0]][v[1]][v[2]].sc});
q.push({path[v[0]][v[1]][v[2]].fr+1,v[1],v[2]-path[v[0]][v[1]][v[2]].sc});
}
}
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... |