제출 #546729

#제출 시각아이디문제언어결과실행 시간메모리
546729krit3379수열 (APIO14_sequence)C++17
49 / 100
2095 ms85072 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 struct line{ long long m,c; int 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; int p[N][205],now; vector<int> cut; deque<line> dq[205]; int main(){ int n,k,i,j; 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]); if(v>=ans)ans=v,now=i; p[i][j]=dq[j-1].back().i; line l={-a[i],v,i}; while(dq[j].size()>=2&&dq[j][0].inter(dq[j][1])<=dq[j][0].inter(l))dq[j].pop_front(); dq[j].push_front(l); } } 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:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:20:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     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...