Submission #42703

#TimeUsernameProblemLanguageResultExecution timeMemory
42703repeatingSplit the sequence (APIO14_sequence)C++11
11 / 100
2051 ms17156 KiB
#include <bits/stdc++.h> #define F first #define S second #define P push #define pb push_back #define MEM(dp,i) memset(dp,i,sizeof(dp)) #define W while #define R return #define C continue #define SI size() #define ll long long #define ld long double #define pll pair<ll,ll> #define pii pair<int,int> #define SF(x) scanf("%Id",&x) #define SF2(x,y) scanf("%Id%Id",&x,&y) #define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z) #define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o) #define all(v) v.begin(),v.end() using namespace std; const long long INF = 1e9+1; const long long MOD = 1e9+7; const int MX=100015; int a[MX]; int n,m; int SUM; vector<int> v; int val; ll dp[10005][202]; int su[10005]; ll DP(int x,int k){ if(k==0)R 0; if(x==n)R -INF; ll sum=0; ll &ret=dp[x][k]; if(ret!=-1)R ret; ret=-INF; ll z; for(int i=x;i<n;i++){ z=DP(i+1,k-1); // cout<<z<<endl; if(z==-INF)break; sum+=a[i]; if(val>sum)continue; ret=max(ret,z+(sum*su[i+1])); // cout<<sum*su[i+1]<<endl; } R ret; } void fs(int x,int k){ if(k==0)R; ll sum=0; ll ret=dp[x][k]; ll z; for(int i=x;i<n;i++){ z=DP(i+1,k-1); if(z==-INF)break; sum+=a[i]; if(val>sum)continue; if(ret==z+(sum*su[i+1])){ cout<<i+1<<" "; fs(i+1,k-1); R; } } } ll solve(){ int l=0,r=1e9+1; W(l<r){ // l=5,r=5; int mid=(l+r)/2; int k=m+1; for(int i=0;i<n;i++){ int sum=0; W(i<n){ sum+=a[i]; if(sum>=mid){ k--; break; } i++; } if(k==0){ val=mid; l=mid+1; break; } } if(k){ r=mid; } } ll res=DP(0,m); R res; } int main(){ MEM(dp,-1); cin>>n>>m; for(int i=0;i<n;i++){ cin>>a[i]; SUM+=a[i]; } for(int i=n-1;i>=0;i--) su[i]=su[i+1]+a[i]; int z=SUM; ll res=solve(); cout<<res<<endl; fs(0,m); }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:108:9: warning: unused variable 'z' [-Wunused-variable]
     int z=SUM;
         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...