제출 #546718

#제출 시각아이디문제언어결과실행 시간메모리
546718krit3379수열 (APIO14_sequence)C++17
0 / 100
62 ms131072 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 struct line{ long long m,c,i; long long val(long long x){return m*x+c;} long long inter(line l){return floor((long double)(c-l.c)/(l.m-m));} }; long long a[N],ans,dp[N][205],p[N][205]; vector<int> cut; deque<line> dq[205]; int main(){ int n,k,i,j,now; scanf("%d %d",&n,&k); for(i=1;i<=n;i++)scanf("%lld",&a[i]),a[i]+=a[i-1]; dq[0].push_back({0,0,0}); for(i=1;i<=n;i++){ for(j=k;j>0;j--){ if(dq[j-1].empty())continue; while(dq[j-1].size()>=2&&dq[j-1].back().val(a[n]-a[i])<=dq[j-1][dq[j-1].size()-2].val(a[n]-a[i]))dq[j-1].pop_back(); long long v=dq[j-1].back().val(a[n]-a[i])+a[i]*(a[n]-a[i]); ans=max(ans,v); dp[i][j]=v; p[i][j]=dq[j-1].back().i; line l={-a[i],v,i}; while(dq[j-1].size()>=2&&dq[j-1][0].inter(dq[j-1][1])<=dq[j-1][0].inter(l))dq[j-1].pop_front(); dq[j].push_front(l); } } for(i=1;i<=n;i++) if(dp[i][k]==ans)break; now=i; while(now){ cut.push_back(now); now=p[now][k--]; } printf("%lld\n",ans); for(auto x:cut)printf("%d ",x); return 0; }

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

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