Submission #403027

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
4030272021-05-12 16:51:40Waratpp123Split the sequence (APIO14_sequence)C++14
89 / 100
1290 ms81704 KiB
#include<bits/stdc++.h>
using namespace std;
long long a[100010],qs[100010],dp[2][100010];
int p[205][100010],n,k;
void play(int st,int l,int r,int optl,int optr){
int mid=(l+r)/2,pos,i;
long long mi=1e18;
if(l>r) return;
for(i=optl;i<=min(mid,optr);i++){
if(dp[1-st%2][i]+(qs[mid]-qs[i])*(qs[mid]-qs[i])<mi){
mi=dp[1-st%2][i]+(qs[mid]-qs[i])*(qs[mid]-qs[i]);
pos=i;
}
}
dp[st%2][mid]=mi;
p[st][mid]=pos;
play(st,l,mid-1,optl,pos);
play(st,mid+1,r,pos,optr);
}
int main(){
int i,j,now;
scanf("%d %d",&n,&k);
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
qs[i]=qs[i-1]+a[i];
}
for(i=1;i<=n;i++){
dp[0][i]=qs[i]*qs[i];
}
for(i=1;i<=k;i++){
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:21:11: warning: unused variable 'j' [-Wunused-variable]
   21 |     int i,j,now;
      |           ^
sequence.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
sequence.cpp: In function 'void play(int, int, int, int, int)':
sequence.cpp:17:9: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   17 |     play(st,l,mid-1,optl,pos);
      |     ~~~~^~~~~~~~~~~~~~~~~~~~~
#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...