제출 #394789

#제출 시각아이디문제언어결과실행 시간메모리
394789Anand수열 (APIO14_sequence)C++14
100 / 100
515 ms81704 KiB
#include <stdio.h> int q[100010],p[210][100010]; long long a[100010],D[100010],E[100010]; void path(int k,int n){ if(k<0)return; path(k-1,p[k][n]); printf("%d ",n); } int main(){ int i,j,n,k,f,r; scanf("%d%d",&n,&k); for(i=1;i<=n;++i)scanf("%lld",a+i),a[i]+=a[i-1],D[i]=-a[i]*a[i]; for(i=1;i<=k;++i){ q[f=r=1]=i; for(j=i+1;j<=n;++j){ while(f<r&&a[q[f]]*a[j]+D[q[f]]<=a[q[f+1]]*a[j]+D[q[f+1]])++f; E[j]=a[q[f]]*a[j]+D[q[f]]-a[j]*a[j],p[i][j]=q[f]; while(f<r&&(D[q[r]]-D[q[r-1]])*(a[q[r-1]]-a[j])>=(D[j]-D[q[r-1]])*(a[q[r-1]]-a[q[r]]))--r; q[++r]=j; } for(j=i+1;j<=n;++j)D[j]=E[j]; } printf("%lld\n",D[n]+a[n]*a[n]); path(k-1,p[k][n]); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
sequence.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     for(i=1;i<=n;++i)scanf("%lld",a+i),a[i]+=a[i-1],D[i]=-a[i]*a[i];
      |                      ~~~~~^~~~~~~~~~~~
#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...