Submission #42701

#TimeUsernameProblemLanguageResultExecution timeMemory
42701repeatingSplit the sequence (APIO14_sequence)C++11
0 / 100
24 ms1160 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; ll solve(){ int l=0,r=1e9+1; int val; 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=0; ll sum=0; for(int i=0;i<n;i++){ sum+=a[i]; if(sum>=val){ res+=sum*(SUM-sum); SUM-=sum; sum=0; } } R res; } int main(){ cin>>n>>m; for(int i=0;i<n;i++){ cin>>a[i]; SUM+=a[i]; } int z=SUM; ll res=solve(); for(int i=0,j=n-1;i<j;i++,j--) swap(a[i],a[j]); SUM=z; res=min(res,solve()); cout<<res; }

Compilation message (stderr)

sequence.cpp: In function 'long long int solve()':
sequence.cpp:31:9: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int val;
         ^
#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...